设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4739|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中& t: J) a" t1 m1 ^9 D
public void spreadMoney(int money){
$ I7 S3 Z5 a) ~- @( K    // Randomly place money in moneySpace, [+ L! `( W# j, L2 t
    for(int i = 0; i < money; i++){
2 h, U5 s$ m7 x$ A) \& q2 _9 z1 p) c
      // Choose coordinates4 r) K- I& t" C9 n, a
      int x = (int)(Math.random()*(moneySpace.getSizeX()));- ^( e5 @, n8 C
      int y = (int)(Math.random()*(moneySpace.getSizeY()));  b1 W; k* \: [+ D

! F* p2 u- [6 j/ Q/ i- `; k      // Get the value of the object at those coordinates
6 N2 x# j( r& V- I      int I;
8 J7 Z4 y& w0 s' c3 ?& l# C" n      if(moneySpace.getObjectAt(x,y)!= null){
4 b8 A$ ]/ H& T7 n        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();& X9 l' O9 b" T) ?6 b+ ?! g
      }
$ o1 [" M9 C* s) H& {) @( r& D      else{* t+ U5 ~% F$ b. K" z3 o# w# Z
        I = 0;+ ^: S5 a' x' C  V/ r& d' h
      }5 y5 l7 M3 }$ R$ F
      // Replace the Integer object with another one with the new value
/ q  a" a9 I7 t2 d      moneySpace.putObjectAt(x,y,new Integer(I + 1));
! R9 M6 n! W7 `7 C3 j' o    }

) b. V9 _- S, z; ~' n% F% @这里面if(moneySpace.getObjectAt(x,y)!= null){
& e, F( c8 ]- m( x! w        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
5 C' k5 o; I/ Q# j* e      }  R7 ~& w0 d. k  E9 C4 d% c
      else{
) t, h% S' B0 U        I = 0;
2 z2 Y! o$ @9 ^, J8 a
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?; z) A7 c/ m# t! \2 h7 F
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-5 11:32 , Processed in 0.013524 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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