设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3883|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
9 F( N9 N2 Q$ E5 s8 c; Kpublic void spreadMoney(int money){2 c! ~, O9 _, |" D
    // Randomly place money in moneySpace
# V. f0 u% W0 n4 P$ {' P6 A    for(int i = 0; i < money; i++){: T, @: D, S& K; b$ q

$ U7 t: o! R" l0 |9 b      // Choose coordinates
: E! d" G2 o+ s      int x = (int)(Math.random()*(moneySpace.getSizeX()));
3 Q2 D" f; n( b      int y = (int)(Math.random()*(moneySpace.getSizeY()));
# d7 p. n+ V4 K0 Q# f+ A7 C5 L8 v0 `( q0 _+ b/ f0 ~
      // Get the value of the object at those coordinates
, n3 U; T/ W5 g2 L  ]' w( e      int I;3 ^* H: A+ C1 T/ }7 F
      if(moneySpace.getObjectAt(x,y)!= null){
4 N/ V3 h: c' E8 Q        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();- \+ }. M5 o$ d
      }
; f) r  F3 }" V! }      else{
. _2 [; m" `; j+ w# j3 g        I = 0;! ]  O4 k9 S+ {7 m- M1 ~
      }
1 _' O( K" D) o- P! U& v      // Replace the Integer object with another one with the new value7 O, N, s5 g) n! ?) a1 x: k8 R
      moneySpace.putObjectAt(x,y,new Integer(I + 1));8 ~3 E- W8 z* q( _3 q/ R
    }

: j2 @$ [& [& k这里面if(moneySpace.getObjectAt(x,y)!= null){# T! i1 G1 ?6 }
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 _  W. P$ ~/ K" V1 q, y
      }
) w4 k; [% x5 c0 ^; e      else{6 s- F' f  }# E# t
        I = 0;

+ Z4 V  t# g8 a- E是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
1 B2 R" e9 A$ ?初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-8 20:07 , Processed in 0.013928 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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