设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3904|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中; r; H$ r; z. Z- d
public void spreadMoney(int money){' I0 }* ]0 P7 Q' O5 C
    // Randomly place money in moneySpace
  t& H. U4 @8 ^    for(int i = 0; i < money; i++){
, f" `9 \  A# v7 Y- g, }
( t( w" v$ W) y2 M; }6 {( a      // Choose coordinates
' s0 E" s5 R; t) j; V      int x = (int)(Math.random()*(moneySpace.getSizeX()));- q. T# F/ N+ R0 K
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
2 R  I! b* q# x# V% z0 w4 C. Z
& Q/ `3 l1 S6 B      // Get the value of the object at those coordinates" E1 C, @) ~. z3 V
      int I;
6 d2 }' {% k9 Z" G! |% I( V5 \      if(moneySpace.getObjectAt(x,y)!= null){9 R/ o0 h' [9 o2 i3 P% E
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();0 k3 [! I* J3 [) a& b) E
      }
# o; [) Z0 ~4 ~, l* B      else{
0 O/ ^' u$ l+ d4 x) e        I = 0;
6 m$ t( @* Y0 m& A# ^3 t. e      }
3 W) x8 z9 K. @0 d      // Replace the Integer object with another one with the new value
7 n) S6 x- L) v( j( ^      moneySpace.putObjectAt(x,y,new Integer(I + 1));
& B2 w5 E1 Z9 S8 w7 ~    }
, r' h; d  S: W! w# p
这里面if(moneySpace.getObjectAt(x,y)!= null){& \5 G+ P6 e0 A8 w: B
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();9 J; r: e! H* x+ h8 m2 J! t
      }6 b' |% ^4 l; d" s" k" Q- _
      else{' I' o7 E: V4 h. U) O6 q/ A
        I = 0;
, X. |* s" t0 y  [" i5 ^% w
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?1 D3 ]7 \% c( [& X
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-17 07:33 , Processed in 0.015784 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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