设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4434|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中1 A1 P5 ^* o3 v, N4 I' K; O5 w
public void spreadMoney(int money){
5 t7 s7 ^# y- d- m9 ]  ~/ t3 X    // Randomly place money in moneySpace
, ]6 E$ {, j, @    for(int i = 0; i < money; i++){
8 ]! o+ K( K/ G5 u; R- N8 a- {% r" ^* i) \0 |. F' G* `# W1 `3 c5 ?* B
      // Choose coordinates1 \: ]( h" x/ q/ J" @* s, J0 S
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
& _: s" O; |2 C/ y      int y = (int)(Math.random()*(moneySpace.getSizeY()));
5 m( J7 r. a' d) C: E, y$ K; j) Q8 \0 e) `& S4 K
      // Get the value of the object at those coordinates# @. X3 W( r3 Z# }
      int I;  D6 e; B/ Q+ z& i6 F1 B5 y
      if(moneySpace.getObjectAt(x,y)!= null){  W/ v4 G- T8 B5 Q
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();9 y9 s. E2 |& o, Q/ o0 O
      }; @% F2 W( S, l$ L& S
      else{3 m2 V; C: ~' y- C
        I = 0;
) B) J. }8 ~  c% q, F) G      }' S0 ^2 Z- R2 p4 E5 @
      // Replace the Integer object with another one with the new value
2 ?0 Z  S9 y6 ^+ R- n! G9 ~6 R5 R      moneySpace.putObjectAt(x,y,new Integer(I + 1));8 `7 v9 Q' b7 ^/ @
    }

4 A. `+ T1 h& O; p% h$ H1 m7 ]! D这里面if(moneySpace.getObjectAt(x,y)!= null){' S, O, T3 a$ ^6 d; H- E4 Q
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();6 v4 V# {; D7 `# P6 ?
      }  r9 x4 N$ {/ C! s. ^# B! k
      else{
! R0 ~* t% {, a7 W- Y" X& ^        I = 0;
+ P4 f8 {2 p. B. t6 u4 L
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
. E& Q' U4 c& `7 Z% M初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-8 02:25 , Processed in 0.015790 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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