设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5102|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
" L" B0 [- f1 lpublic void spreadMoney(int money){$ k# [- }: D& h2 s) |! ?
    // Randomly place money in moneySpace
- x" F* V" p. b* A    for(int i = 0; i < money; i++){
2 C! U- H6 f. S( ?& g/ u2 a* `2 a0 H& U( T
      // Choose coordinates
" b; S2 i; R8 S0 h0 s/ c( V0 B      int x = (int)(Math.random()*(moneySpace.getSizeX()));4 J" `6 m' O* g  ?' K; ]5 T7 B1 h' y
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
+ a5 X4 r  |" W. n6 `1 |" p. ~- c. d
      // Get the value of the object at those coordinates
( X( O# f  n- L; }1 ]& }      int I;
# u7 o! j& P- Q% [      if(moneySpace.getObjectAt(x,y)!= null){
3 ]/ R  V, X6 k. u, |6 Q3 R        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();: ]2 L7 f- r" m
      }
1 m3 X4 J# E/ p8 n. O" s/ J+ c9 |" C      else{) s% b# e* t; ^5 U2 \2 N* K' h' W
        I = 0;7 z/ `- P8 M: E
      }
  f7 c$ w, w) ^! y6 S      // Replace the Integer object with another one with the new value1 x8 _9 ]% ~& t: j% k
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
5 F  q; Z9 x+ j    }
4 D* e8 t. O$ q/ ?; V' v
这里面if(moneySpace.getObjectAt(x,y)!= null){
( i# w; N) x- N8 h- l% L1 _        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
% [3 U4 D4 }4 a% f9 j) K0 E/ m5 H. \2 t7 d      }9 F. ~! u- ]& _& k
      else{8 ?& Q; d- D2 {
        I = 0;

) H& I: N8 {  t3 a& s! q是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?5 N. V/ D& U# n4 P
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-25 18:59 , Processed in 0.013737 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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