设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4539|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
. ]4 d% |( X' w# @5 v, tpublic void spreadMoney(int money){, l2 C- r- t. q
    // Randomly place money in moneySpace
; _) l  E2 x1 b4 \    for(int i = 0; i < money; i++){
8 _5 d1 C$ M% J- R( H* X' s" d' a5 i% s+ o8 a
      // Choose coordinates: x" B2 A$ h& J+ _2 m" b7 }
      int x = (int)(Math.random()*(moneySpace.getSizeX()));" U, g* k) X& p6 \
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
  [& `8 T& a) H( S8 X
* h. ?2 t( b% d) c% _      // Get the value of the object at those coordinates# A8 J, w3 \3 _; B3 @
      int I;. R2 P- D/ Z/ W3 J
      if(moneySpace.getObjectAt(x,y)!= null){- Y: }% a3 U: \' t8 K
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
/ _6 c6 a+ s4 D+ {      }6 z0 E) a  q4 U' _; I
      else{
# q& F& W2 Q+ l# G0 W7 c        I = 0;/ e) o) U" q7 C4 ]1 v
      }
1 ~4 N' E/ j7 d) Z) G6 T( [      // Replace the Integer object with another one with the new value+ K+ Z1 l* M/ E! q6 C
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
" O5 q& `2 p8 R1 P7 k0 q+ l' b    }
" O0 l& j* T8 ?# T2 g! x0 `( ~
这里面if(moneySpace.getObjectAt(x,y)!= null){( ~) v2 K' q1 a; N  D4 Y
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
0 i3 r3 Y9 T9 J; Z" y1 K; N# w      }! }# z6 b; q) j+ F+ }
      else{
9 e( b: x6 S& n- \        I = 0;

; W3 U" K% k! v' e/ [! C: d是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
0 J! c, C2 a" X  i初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-2 20:58 , Processed in 0.637821 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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