设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4636|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
' L+ T' l0 a; e  T6 Z  C: qpublic void spreadMoney(int money){
) `3 _/ q! U( d2 r2 Y2 q  n; [( l    // Randomly place money in moneySpace
0 ^7 C  A, c0 v0 [* P! ?    for(int i = 0; i < money; i++){
( o7 U* B+ d- o  @5 L5 m! P" b, n( y# }! \/ d& H
      // Choose coordinates4 k5 A0 m* F& A' g4 V
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
  E0 s% Z2 ]1 o$ l- ?- ^. L      int y = (int)(Math.random()*(moneySpace.getSizeY()));
& R4 N! v, [" e7 e8 v
  O- B* j" n, n' p0 e4 a2 `# K      // Get the value of the object at those coordinates
7 Y" @7 L9 B1 g2 l6 F      int I;
% p3 Q2 E& C3 S' W3 u, T      if(moneySpace.getObjectAt(x,y)!= null){$ y7 r5 ?2 D' s4 t
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();4 X% B2 {* r/ X7 C: w; S
      }2 u3 E% P" N5 D! R
      else{& O# i" [' Q6 B' H, \7 E# u- k4 R
        I = 0;
. {6 r7 Q, C; @" M; H% x/ N+ {      }& Y, @8 T5 m% }. t, P
      // Replace the Integer object with another one with the new value
2 y% L: m& h" j% R- d5 u, ^' o/ @8 P      moneySpace.putObjectAt(x,y,new Integer(I + 1));
) h1 [- p" e$ m( b/ t    }
: X! {% v" [& [! f7 ^3 j$ h
这里面if(moneySpace.getObjectAt(x,y)!= null){
* |3 E& ^( V. L/ D/ a1 U- i7 y        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();' V" B1 x0 k& x
      }
  a* X$ `6 d. U- E( a/ _, q      else{, t: G( j1 X6 `( @7 F8 q
        I = 0;

, u& O- x" l& g+ Q是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?& u4 j. r# B- f
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-5 07:12 , Processed in 0.016374 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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