设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5083|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
) o4 O" W  h: s5 vpublic void spreadMoney(int money){
8 v, f5 \3 u* |    // Randomly place money in moneySpace9 [( N' Z7 C* z8 Q# k& }0 i3 Y
    for(int i = 0; i < money; i++){
* Z2 R" z/ U6 W! ~) N2 d7 J" Z' z: |% O. g. Z4 B; i
      // Choose coordinates/ O/ A' o  j+ r5 x6 O
      int x = (int)(Math.random()*(moneySpace.getSizeX()));5 i( x2 D( r1 i; g$ I, m3 y3 \
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
* u8 v5 c$ j  ~; `9 u' D) T
8 b) k6 [; U% |; u. J1 k      // Get the value of the object at those coordinates
$ k2 G: F" ?0 L. {: g5 @- I      int I;
- `5 F: h8 ^; V9 G3 O/ @      if(moneySpace.getObjectAt(x,y)!= null){
( b1 ~" w0 [4 N' J. b0 @0 p: _9 M        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
! P  u7 P' l) z. _" W6 u( L$ n      }$ ]- b8 E' f) E2 T5 _
      else{
) ~# L7 `" ~0 V. C- E        I = 0;
9 }* `1 t3 S/ o5 \/ t. ]9 ~$ v      }/ A; ?1 `8 O" O
      // Replace the Integer object with another one with the new value
+ I  ?9 |1 H# g2 \4 _2 y" z      moneySpace.putObjectAt(x,y,new Integer(I + 1));/ M5 V4 x6 p8 g+ c" L3 U  J
    }
' i" R6 E8 }2 C: F
这里面if(moneySpace.getObjectAt(x,y)!= null){" ~9 F7 J0 g" n$ @# ?) n
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();( P+ R: x2 M) _
      }9 v6 t% D8 ?& V% I% j
      else{
6 m) M# c7 S2 x& w; W7 k        I = 0;
6 A9 V/ k' ?( v. b2 k
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
& _; \: r0 ^; B  w) H! f% u初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-20 03:17 , Processed in 7.352448 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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