设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2753|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
2 k, i) [4 X( P5 Q* y6 c: apublic void spreadMoney(int money){
) A5 t0 E) M. Y5 R3 K8 `4 y    // Randomly place money in moneySpace
+ e0 I4 Z1 X; w1 m3 {. u    for(int i = 0; i < money; i++){
. h# A0 z* ?5 P( y% e8 ^) v
' J8 Q& j3 a) |/ j- V# e      // Choose coordinates
. S1 u* I3 u2 f* @      int x = (int)(Math.random()*(moneySpace.getSizeX()));0 v% p9 t/ I. W# {0 D
      int y = (int)(Math.random()*(moneySpace.getSizeY()));2 `, S( V2 D7 w1 [; h" s! n4 L8 y
# W8 n" h( r  ?" G- u4 J+ y5 p$ U# T. O
      // Get the value of the object at those coordinates
# [/ D  ?- h* @% j2 t2 ]      int I;
! W) m* W" V0 V2 b* `9 t      if(moneySpace.getObjectAt(x,y)!= null){4 e+ `' C, g! D- o& k* g
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
5 x/ |' w: _$ t8 g6 u& ~! |, N* o      }
/ i8 C8 O' p0 u+ A8 V  K8 w9 ~& C      else{
* p/ B. l" @% ]2 v2 N+ V) a2 {        I = 0;
9 e1 e0 U! U8 g      }+ z( b* O% P7 T1 g* @
      // Replace the Integer object with another one with the new value$ g! J* T, j" j0 P- y* r( q/ Q
      moneySpace.putObjectAt(x,y,new Integer(I + 1));+ i6 R, e% _+ n
    }

, f7 i- _" Q! E9 @这里面if(moneySpace.getObjectAt(x,y)!= null){. l* ]/ M) A7 a, d3 n
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
! w9 K( {# u* C6 {5 n+ n1 z      }# a% k( W2 E' H
      else{
& w! x8 ~! }0 H9 ?7 P3 S; C( }        I = 0;
+ e! f% h" Q: e" r
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?# [: F/ D5 t$ H# q  U
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-17 16:10 , Processed in 0.012843 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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