设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4281|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
; A( F  T: ]+ n( l8 s3 dpublic void spreadMoney(int money){
8 p$ f1 }' j' ]* U    // Randomly place money in moneySpace
* }; @, o* W0 g5 X) J" a    for(int i = 0; i < money; i++){
5 H$ @9 [+ `$ V! P8 f
; P$ S5 A! v, _; f& {% ~7 E      // Choose coordinates
+ Y$ D1 j4 P& k* s, L) h+ E      int x = (int)(Math.random()*(moneySpace.getSizeX()));
1 D1 }: O; P7 k$ d, S      int y = (int)(Math.random()*(moneySpace.getSizeY()));) e6 E: w6 T8 J- g% l8 @( D$ A
  s6 E# G& u+ G
      // Get the value of the object at those coordinates
2 h1 |+ D8 u, ?1 V. L$ j      int I;
* K! Z" I: {- U( u* |      if(moneySpace.getObjectAt(x,y)!= null){1 d! G% S3 Y) o4 `7 ?+ b
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
2 x- q2 p7 W0 [9 k; Z      }
2 N+ e  W) T; R* x      else{) y6 ^/ T" J. F% Y4 V* B
        I = 0;
0 B/ G! g) T8 T" X6 E6 S      }6 A0 S) I: \$ C+ W, L9 i
      // Replace the Integer object with another one with the new value2 Y: y3 d& u& }6 e' I, X2 D3 i4 Q( X
      moneySpace.putObjectAt(x,y,new Integer(I + 1));. c, W7 u6 {2 K! T7 j( m' }3 O+ Q! a
    }

# s0 {) v3 O9 b这里面if(moneySpace.getObjectAt(x,y)!= null){$ O( y3 t& J+ g7 `: f. m
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
6 ~/ f$ j4 _5 f# i2 y      }8 q1 B6 O  A( f7 F
      else{% _& a/ c* _9 z% ~9 c" ?
        I = 0;
( t9 ~, D5 z7 R
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
3 E1 m/ U8 P, _9 y! g" I. \初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-1 14:30 , Processed in 0.016313 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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