设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4399|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中; r/ r7 K( |0 ?# J0 }( O
public void spreadMoney(int money){
# p1 B$ C9 r2 N4 @* V3 a! a    // Randomly place money in moneySpace2 R0 N, n- K: P6 I
    for(int i = 0; i < money; i++){. _6 y  }$ I. H+ N

6 t2 T: _* v3 O9 G      // Choose coordinates9 N' y2 ~' B; G0 S
      int x = (int)(Math.random()*(moneySpace.getSizeX()));1 V8 O/ j+ p" W8 q. l8 i9 {2 ~
      int y = (int)(Math.random()*(moneySpace.getSizeY()));6 t! w  x$ g# }$ q+ t$ c

) S3 E+ m6 e2 H) z( W( a      // Get the value of the object at those coordinates2 D/ @& K/ \* `( j7 P( S
      int I;5 p2 K  z. ^. U4 T
      if(moneySpace.getObjectAt(x,y)!= null){/ S* P; @% C9 _8 P* L0 S8 u
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();7 w& b" a- n1 R9 Y& C0 j! q
      }
0 V3 A9 w9 f4 Y/ B8 T9 }& }9 W- s& @      else{4 ?8 o, S! I% e3 ~
        I = 0;
* M$ r0 p6 B2 ?; \1 u" b( F- ^      }0 I' A! f4 C0 P' |& U9 d
      // Replace the Integer object with another one with the new value  o. k, a4 U# {* s/ J
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
* {4 r2 ]' |% K- K    }
6 ?1 O/ N0 A! Y$ C5 m( |
这里面if(moneySpace.getObjectAt(x,y)!= null){
8 N7 |# Y) i- [+ e: r        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
" D' v3 q$ n/ E- |      }
: M7 g$ a2 q0 O5 u& f. }# q6 A! a      else{
3 G+ N! d+ }! z! ^3 n, s        I = 0;
( w' m0 G& X1 k8 ^& N
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?. c' T/ \9 O. W) l% `& W
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-18 20:55 , Processed in 0.018185 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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