设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4109|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
/ t- l! r; L  c  j9 Zpublic void spreadMoney(int money){
2 j2 j% i4 b, B  J    // Randomly place money in moneySpace
$ _  i% n  j) _2 `    for(int i = 0; i < money; i++){* c/ E5 G7 z6 p: ~7 |! w
+ M# y- z3 |8 e9 s( [  \' X+ ]
      // Choose coordinates; l& M$ ^* O2 O
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
) ]% L9 Q0 @$ k3 o9 y      int y = (int)(Math.random()*(moneySpace.getSizeY()));* ^: e3 |: ~. l7 I$ ]
" i" v- c) _9 c
      // Get the value of the object at those coordinates+ z7 C8 t4 _& e- u0 \) o. ~3 A
      int I;
( N; T$ M* L+ M      if(moneySpace.getObjectAt(x,y)!= null){
$ U% k' p" G; k; B( e) j        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();$ u9 q& f# r3 S  _' G4 u
      }4 @4 F6 a8 |4 H* j
      else{( y5 Y1 f0 U. b: {& w
        I = 0;
5 `$ Q/ J' L: q+ X3 O      }
  o, }9 {/ Y: [6 h" d: ~* h      // Replace the Integer object with another one with the new value
6 @3 y6 @' D: U) W( T1 d$ ?      moneySpace.putObjectAt(x,y,new Integer(I + 1));
8 [( n# [6 t, H/ d6 s) J0 T    }

  s2 X; Y  ]( h& i" ?$ H; z这里面if(moneySpace.getObjectAt(x,y)!= null){
" S" d- [+ B# g+ L        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();9 k* U$ d. _8 A' Z, @8 Z+ y
      }$ G" c" \" v* ]( q
      else{( v1 v) j& o% s* i
        I = 0;

8 q: l, I2 T& m+ b! @/ h! D5 `( _. G是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?: X! |& W! n% m7 D+ ]1 I- u& l
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-16 06:42 , Processed in 6.231024 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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