设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4852|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
' ^' B: n- u% H# F: H! \. G3 j$ epublic void spreadMoney(int money){
$ E2 [6 F8 Z" ~    // Randomly place money in moneySpace
9 A, D6 {, s9 T' P2 e    for(int i = 0; i < money; i++){( F5 V4 V/ e$ b4 s, p

5 b' t. m* ~, m( ?  O3 _      // Choose coordinates
# ]( B$ `1 v/ K# y      int x = (int)(Math.random()*(moneySpace.getSizeX()));* P6 ]8 y/ R+ G' ^" x$ v; O! {
      int y = (int)(Math.random()*(moneySpace.getSizeY()));8 p, N9 ~2 I. K$ A2 [2 R. L5 r& E

0 ~. U+ e) |) [: y4 L  w      // Get the value of the object at those coordinates
1 k( p2 k6 u* ]5 U( Z( o& `      int I;
5 _/ v2 n, m4 z4 h9 b2 _( p      if(moneySpace.getObjectAt(x,y)!= null){
9 ^: [9 @7 Z( ]" U        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
- X2 I% a9 S1 y5 L) i      }% l5 C4 e& _7 G. y
      else{, o1 W6 p# b* S
        I = 0;9 N7 y6 h2 O" K
      }
# Z. e. U! g9 @4 Z1 j      // Replace the Integer object with another one with the new value
# U% `. A! \$ z. I      moneySpace.putObjectAt(x,y,new Integer(I + 1));- F4 P" G5 j1 K/ d8 h9 F
    }

" z2 |# X0 b7 o  @" G这里面if(moneySpace.getObjectAt(x,y)!= null){% m. Q5 t& J+ ?* x
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();( a2 M: p7 Q0 e) b7 O: H
      }
/ X/ ?. |' C  M( I5 W, Z( ~      else{
/ C/ A. f. I' y9 m) N, o# w3 N        I = 0;

: R7 u9 G5 W. r& m/ R1 g. [是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?2 b7 K) r; {  I  g" k" m$ v
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-9 17:17 , Processed in 0.018996 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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