设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4474|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
9 v. N* c2 s, K$ u, Cpublic void spreadMoney(int money){
4 K) q; N, v7 h9 Y" c8 c. S    // Randomly place money in moneySpace
$ J! J) K, j7 g0 n5 V0 B2 d. r    for(int i = 0; i < money; i++){: i: g3 U  E0 g9 a

: e$ Q1 I2 W/ @2 E& O      // Choose coordinates
: @9 m+ n% T2 k0 c; Z      int x = (int)(Math.random()*(moneySpace.getSizeX()));
) y: K0 u7 F! E( C+ p) Z2 k, }  ~      int y = (int)(Math.random()*(moneySpace.getSizeY()));+ c0 y, H" s& q+ S" e9 `3 p
. D' Y. c! h% u/ Q( x9 v
      // Get the value of the object at those coordinates
  `+ T- H7 _, E$ L- z. K. m: d- Z      int I;
+ A+ }+ ~+ |8 a4 l6 _      if(moneySpace.getObjectAt(x,y)!= null){& {; ?6 d& J* E" z
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();( L# V- S# E" r' e
      }9 Y2 U1 p" C, J; H7 H
      else{8 r' P! D8 u/ ~! {2 _" N# G
        I = 0;
8 }% m: T, x8 C! ?. F8 t# L3 {      }6 V9 b3 T" b# P) n
      // Replace the Integer object with another one with the new value
0 @4 F$ o" Y4 k8 s; b* B8 k      moneySpace.putObjectAt(x,y,new Integer(I + 1));
5 ~) [2 i/ Z( o6 e. |    }

- Q9 L2 h. A  a; g; j1 u2 u- h+ J这里面if(moneySpace.getObjectAt(x,y)!= null){
) q6 P1 g! B$ _! p        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
1 l, U, c2 t7 p% I% x      }# u5 e. S% j5 {. e+ e! o  F
      else{0 H/ |0 t& }$ o! v. k4 H& J: g
        I = 0;

: i0 ^" ]8 X* {/ _, u% t4 e是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?; L) D: n( ]5 o! N" ?
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-15 10:03 , Processed in 0.015239 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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