设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4847|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中( Y7 w. h/ R. O7 G
public void spreadMoney(int money){
0 p3 g4 C1 w; ~1 q0 C( m* g4 |    // Randomly place money in moneySpace
' }" W! N* ?& g% V; }& }3 X0 ~1 [' {8 ]    for(int i = 0; i < money; i++){0 ~, F6 d: s' s

4 a6 B' D$ v% ^3 Y) ~" K0 c      // Choose coordinates! c+ p3 W5 m2 l
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
& o' S7 g8 F) z7 c3 L: O; _, p      int y = (int)(Math.random()*(moneySpace.getSizeY()));4 Y6 k2 ?, P/ _+ w3 G' A

7 ]& v  j9 k/ a; R7 v      // Get the value of the object at those coordinates( {9 U" ?9 i5 A5 g: p3 u
      int I;6 u% K: Y5 s! t* m+ c
      if(moneySpace.getObjectAt(x,y)!= null){9 g8 u. H8 y" r8 g
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
8 T( I, j1 a9 ^      }
6 w& B* {# \# }* q* I* N4 T      else{0 B4 S+ w! z" @& H* F% S3 Y; h
        I = 0;
6 ?) @3 W6 Z0 P; p      }: n% \9 f1 t- I3 w
      // Replace the Integer object with another one with the new value
9 B2 q; W0 o0 z# T: p. e      moneySpace.putObjectAt(x,y,new Integer(I + 1));7 C9 |# ^- v; `& V; ~" D/ I
    }
) _5 r, ?/ @4 j
这里面if(moneySpace.getObjectAt(x,y)!= null){
+ t3 r5 d" K6 x; t5 O        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();+ g" o; T# e9 f
      }
% F1 H! p, B8 @2 X      else{& o$ n! f/ b2 c% f  |& m4 l
        I = 0;
! B! Q1 s! j7 |! |) P
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?7 ^- n) A0 l1 B3 J+ Z3 ]% D4 a
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-7 22:22 , Processed in 0.021456 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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