设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4932|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中: N- E6 A1 S% \. M; R- K: B# ]
public void spreadMoney(int money){0 Z/ l" |% V3 D7 w- y# q! _7 ?4 H; D
    // Randomly place money in moneySpace- e+ x) b' _) ?9 f
    for(int i = 0; i < money; i++){
6 K  `8 w7 m. [+ k' p& c
! L6 N: p$ |: o* H/ C; s      // Choose coordinates7 X0 g  Y1 H: E1 e/ o
      int x = (int)(Math.random()*(moneySpace.getSizeX()));- ^' ~; C9 i- \& ^3 s
      int y = (int)(Math.random()*(moneySpace.getSizeY()));& N! U! {% J6 b/ V$ }8 P7 f/ |

" J, u6 e* f% O, J# y8 N      // Get the value of the object at those coordinates( S0 P, Y" A6 E" y
      int I;. e( E& a+ B7 x( i! Y
      if(moneySpace.getObjectAt(x,y)!= null){
( n% s, S' C; m        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
5 @1 _  t3 q2 Q( M' J      }" f% O1 b9 q- O4 j7 Z3 {* ^
      else{
2 ?( V% Y. Q2 a5 y        I = 0;
7 `! B! L: g; {  g      }
# f7 ?1 }) b, S$ |& M& Z' q      // Replace the Integer object with another one with the new value
( m- Q  y+ K# p" U9 |      moneySpace.putObjectAt(x,y,new Integer(I + 1));
7 k6 D3 a3 k6 d. Z    }
- A0 W! c4 L7 n
这里面if(moneySpace.getObjectAt(x,y)!= null){
/ w% P1 ~0 N' O9 W0 A( w4 J6 b        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
! k6 F3 \, u5 F1 k+ `      }
3 B) w7 `# j( }% A/ o      else{
9 n: y: r" N+ |3 u; c) e        I = 0;
1 v: h$ h: A" x. C
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?6 j2 x" R: L: _3 t0 d! H& N
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-28 02:52 , Processed in 0.024869 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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