设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4532|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
$ P! }0 E7 d& ipublic void spreadMoney(int money){
1 W7 A; F$ |- ^& |2 O& D    // Randomly place money in moneySpace/ \- D" g' E& F' O/ V8 J& h6 b
    for(int i = 0; i < money; i++){- x, u0 G& t, l
9 N8 a* Z8 p) i% U; o6 c* b. ?
      // Choose coordinates7 E) j/ `1 {. @
      int x = (int)(Math.random()*(moneySpace.getSizeX()));1 F! p3 d, U3 T. u& t3 }0 ^/ H
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
# s4 Z3 U+ ]4 Z( W
  Z& L) T7 V4 g9 S0 h5 I6 G      // Get the value of the object at those coordinates
  L  ~+ ?% q; {6 {+ p; X      int I;
) z6 O+ u0 C+ g& Y% Z$ j0 y      if(moneySpace.getObjectAt(x,y)!= null){9 {% |& |  {+ k. N0 o2 G& m3 ^
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
% z: E* I4 x& n3 t+ i      }
: H; V2 k2 J, l* Z& s      else{$ l* m4 Z, d0 L
        I = 0;9 s9 T" G- `- _8 c3 ]/ W: i
      }9 C; b1 i. j9 h* v
      // Replace the Integer object with another one with the new value# S8 r" _- i2 k4 E
      moneySpace.putObjectAt(x,y,new Integer(I + 1));! [1 F" a# j0 i5 ]" g8 p2 q8 S
    }

! o" U7 d9 _8 s" |2 f% k/ `5 s这里面if(moneySpace.getObjectAt(x,y)!= null){" a1 U! j& d6 U& \/ O5 f
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();# r8 W! W2 p; P- ~6 l( f4 X; G
      }9 O6 e0 p+ @4 Z, R0 ~- F6 T! P
      else{' e! i4 @, z9 b1 P
        I = 0;

! x# m; e3 N2 k- ?. W4 q是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
* z* Q6 Y1 z4 n+ x$ ?" e* I初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-30 08:46 , Processed in 0.015266 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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