设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4519|回复: 0

[求助] 应该是个简单的问题

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中: }  h3 I$ p) @
public void spreadMoney(int money){
4 ^9 F' I1 W' H" K    // Randomly place money in moneySpace' H$ c8 q5 E4 T+ i
    for(int i = 0; i < money; i++){4 I! A" D( d$ |0 h3 J1 Z
- e4 {0 D% E3 o- A0 J+ s* u
      // Choose coordinates
7 T/ M2 a2 r1 }: v: A' _; w      int x = (int)(Math.random()*(moneySpace.getSizeX()));; D+ ^6 D5 P9 f0 n7 k: W7 W7 o5 L+ V
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
: W9 B1 O4 H( O" b8 p- r+ B/ G  E$ |' u5 E/ [' a" \3 X4 C
      // Get the value of the object at those coordinates: r6 S9 t4 _3 y) D9 w9 }7 Z
      int I;% g" `' B3 x) A% I/ i" i' z& I
      if(moneySpace.getObjectAt(x,y)!= null){/ {7 A) l9 w7 T2 E& I* }3 T0 A0 }% i
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
7 U  F) @2 ]" q$ `# x) l      }
7 W- q8 X& c8 ?! ~0 Z8 U) S- \      else{
/ u9 e1 [% N/ d" v/ z5 Y9 M( N# z        I = 0;+ z$ H( e3 b5 u- {$ G1 @, P5 f
      }
: s; t6 q7 `8 P0 K! a      // Replace the Integer object with another one with the new value
+ I! T" G) Y  K4 r! Q4 i& V9 V( @4 X      moneySpace.putObjectAt(x,y,new Integer(I + 1));( T; p9 f4 v/ O$ k* k% V
    }

  \1 n2 v% |3 z) |2 n( x$ S这里面if(moneySpace.getObjectAt(x,y)!= null){1 {- w8 v# k9 X* S7 P
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();4 h9 h! r  k! d0 J( l1 Z7 N  I3 b
      }
) d) ]6 v6 L& G. B1 d      else{
- D0 N- S. W& }4 s9 y        I = 0;

7 F. g7 O( N( V6 \- j/ ^! [6 w是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?8 }- h! f! }) W, W; v) z: u
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2025-12-27 13:32 , Processed in 0.016207 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表