设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3865|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
2 j/ e. l, I, m0 L4 E" d' x( N' \0 k/ Dpublic void spreadMoney(int money){
& p- P' m0 ]6 O/ \    // Randomly place money in moneySpace" S2 y( J  B: s% c( J2 O
    for(int i = 0; i < money; i++){, _: m$ a9 |( K

7 K( \, |6 Y# M- ^( L' x      // Choose coordinates( m9 J5 b7 C( |" h# c! s
      int x = (int)(Math.random()*(moneySpace.getSizeX()));8 j3 T8 h8 v' h/ m$ s$ J( y" P
      int y = (int)(Math.random()*(moneySpace.getSizeY()));  P3 R5 ], J) e3 n8 N& \$ w9 ~

  L/ g  X1 L" O      // Get the value of the object at those coordinates
5 S, s" u1 Q3 x0 T- Z2 r( O      int I;
5 W" ^) f2 _0 W5 l8 h( E7 `9 {/ [      if(moneySpace.getObjectAt(x,y)!= null){
/ [: z' p) Q0 @; U( N3 M        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 c8 G9 N2 K. j  h% f
      }! t* b" i) o$ R. M' A
      else{
9 X- @- I) i& \+ a+ k, J0 x        I = 0;5 Q$ X9 z- H8 Q, ^
      }
% ~' N$ S9 ]2 |! j      // Replace the Integer object with another one with the new value# u2 T) e! k% H* X4 J7 w, X  P
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
; m/ M) a2 m8 w2 d8 s8 G* T. [    }

. P4 z0 B8 y+ ~2 A这里面if(moneySpace.getObjectAt(x,y)!= null){4 J# m" N( A3 m* v
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();/ c/ R  C* V8 {  z$ i
      }; k8 O6 x- [3 L" @8 q
      else{
+ d# ]+ B. V8 L- \' _5 G) j" o        I = 0;

6 K* D1 p0 S6 [. o7 W) r) p1 m+ Z是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
- y0 i1 ^. e! E* ]初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-4 05:56 , Processed in 0.013933 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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