设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5314|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中' S  e: {, U; t7 a& N+ z
public void spreadMoney(int money){9 _2 e' C: U& R1 M- V& e7 P
    // Randomly place money in moneySpace0 b- _) C& U1 z  x: X' `9 Q
    for(int i = 0; i < money; i++){
6 q# c6 R) s9 ^6 t/ t/ L* |" b- k) l+ P( G3 T' J7 ~# k
      // Choose coordinates
% ~( A8 Q: l6 f* K8 J; y6 Y      int x = (int)(Math.random()*(moneySpace.getSizeX()));
, _/ d4 e7 {, r4 j      int y = (int)(Math.random()*(moneySpace.getSizeY()));8 j; d8 s+ b# {8 O. R* H
* v* F2 @1 U2 p8 b* o
      // Get the value of the object at those coordinates
" I3 e! \: c2 T      int I;
: i: M- J, F0 V# {* I" C      if(moneySpace.getObjectAt(x,y)!= null){
: Z. a" P! D- J        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();( H4 L4 y- b9 Z
      }. o$ E3 I8 v. g; L/ _" x% Z
      else{
5 W9 |8 [: X5 R8 O2 ]0 c2 P1 D        I = 0;: V: L& P3 k& ]! R
      }) o$ `  Z4 H1 t6 Y6 k
      // Replace the Integer object with another one with the new value9 B- ]! A, X3 l. _, N% {
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
- t' y0 v4 m+ n/ U    }
: s3 u% |6 c* M  E5 n; {2 G
这里面if(moneySpace.getObjectAt(x,y)!= null){
9 f* w" f4 f0 e" Y$ A( f        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();3 j+ g7 I3 O- N# ?) I5 n
      }
" B% A# B* j+ ?, {, u3 o      else{9 v/ I2 q& O* [4 m1 p: ]$ ?
        I = 0;

0 E$ R* K3 l. y6 i3 k# B是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?# g: @# Y; P6 A9 n  O$ a
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-14 05:16 , Processed in 0.018520 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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