设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4313|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中# s, A2 h% E/ N, o; @
public void spreadMoney(int money){
2 ~" x! t$ R" }    // Randomly place money in moneySpace
0 d. o* ^* ]" o- @% Z$ [3 [    for(int i = 0; i < money; i++){4 R5 S5 N! u9 A
9 m# U8 e+ t3 ~" u4 k4 K" c4 Z1 a
      // Choose coordinates5 _/ o; l" X, r( s
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
6 J+ V3 ~: {, }; U      int y = (int)(Math.random()*(moneySpace.getSizeY()));5 L1 o  O& Y) }! P! S  r8 @
* R* ~! h, b9 A/ x. x
      // Get the value of the object at those coordinates
3 |/ E* v4 P( r& b1 s1 `+ c      int I;) f$ N5 F- w4 C* [6 N+ s0 [
      if(moneySpace.getObjectAt(x,y)!= null){
; [  t. K; M7 y& i) l        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();' j9 M4 U+ l$ A) _; h1 W
      }* r- V0 l8 {1 f0 o
      else{+ J+ L0 Y  ?7 X: \2 ?
        I = 0;
" n9 C4 V# T% H* f! X- b' _      }+ o7 ]7 Y; _" t/ g8 V5 p
      // Replace the Integer object with another one with the new value$ P" L  V2 n/ c) ]
      moneySpace.putObjectAt(x,y,new Integer(I + 1));- E9 Z; Z4 Q" p" w& X" r/ l
    }

7 x& d/ \7 ~, a. n: [这里面if(moneySpace.getObjectAt(x,y)!= null){! F. p8 \5 i  B1 X
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
- E/ s- q2 P# |1 k5 _      }
6 p4 [& ?2 C/ S+ P! A: K( m      else{2 a. D+ o' ~3 M! g2 H1 d* u" T
        I = 0;

. J% F2 S2 E) X是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
( y6 A3 Z* @' P# P初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-6 02:30 , Processed in 0.022803 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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