设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4558|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中; X* `2 w4 H# m) G" T: g0 v; S
public void spreadMoney(int money){
2 a* F* j9 n, m) E0 |    // Randomly place money in moneySpace
  ?- d- p: l% `7 F1 q    for(int i = 0; i < money; i++){
# j5 V' d9 E; s! r: u
8 p1 `9 B1 f+ w7 h2 m4 m      // Choose coordinates
2 ?5 m) p1 }; ^( Q. t7 _) Y      int x = (int)(Math.random()*(moneySpace.getSizeX()));4 N% G2 M  U4 F- F) i( e, g) {) A
      int y = (int)(Math.random()*(moneySpace.getSizeY()));" A2 T8 w& o1 U0 e# ]' u

9 g( q9 w$ ~# l2 G- O      // Get the value of the object at those coordinates" L& w: q3 N3 k* }- A
      int I;
# Y) I; t7 B8 ?0 }( L; v; C      if(moneySpace.getObjectAt(x,y)!= null){/ ]3 M/ @3 o* O$ b& ?
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
" d( Q2 `2 o4 v      }1 C( y( d% {/ a, t6 b" y0 `# F/ u7 l
      else{, N% u: N1 {: u& l( n
        I = 0;
9 z7 c/ _. H1 l3 M+ A2 t, @      }
, a; f5 j! r% W- S% d, P      // Replace the Integer object with another one with the new value
: y5 Y" k4 o3 h      moneySpace.putObjectAt(x,y,new Integer(I + 1));5 s  M# S; |' }; X, y& S* }
    }
$ Z$ R  C1 M8 A+ O5 ]
这里面if(moneySpace.getObjectAt(x,y)!= null){
; W4 j0 `9 f8 v        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
4 H8 X+ _8 }! ?9 Q& m, t, B* r9 w      }
' n6 V- p, d3 n% H$ T      else{* [3 U* @1 U$ b1 e7 L! U6 R' |
        I = 0;

8 [$ W' W2 a2 u9 z6 d是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
9 q+ M$ t$ N7 R: v+ ]+ p初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-13 09:33 , Processed in 0.017344 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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