设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4427|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
6 ?, t' r, W- l' w2 S/ l' kpublic void spreadMoney(int money){0 H0 d! B( |% r! \0 t
    // Randomly place money in moneySpace
8 w& ^# w1 v$ M; f) l2 n, L8 N    for(int i = 0; i < money; i++){7 ?/ v  f7 y" Q

% u6 k7 y2 C6 t- Z7 w      // Choose coordinates
! \) o$ B8 E- S6 n  D' k      int x = (int)(Math.random()*(moneySpace.getSizeX()));* d. p5 n- L% A3 t% R' N' d
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
" u5 Q/ p6 s- o) V: D' _+ ]% v
2 c# y: s! _- F+ r- v      // Get the value of the object at those coordinates
; \6 O7 W; C4 ~) D9 E      int I;0 U" l# A, j- I( m
      if(moneySpace.getObjectAt(x,y)!= null){
( H; L. i  f5 v& V6 d/ X+ D! A        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();) [: L3 ?9 P" r( `5 v& k7 U
      }6 w  Y; S( N0 x
      else{
+ O& Y1 ^) E& Y; k- \7 K6 L        I = 0;
, j6 Y/ E3 ^. Q9 r* t      }- L+ P7 L) E  `  H0 B
      // Replace the Integer object with another one with the new value
  r* i" X. P2 P9 B+ b! N6 U) E      moneySpace.putObjectAt(x,y,new Integer(I + 1));1 M1 V' g3 }5 E' }
    }
0 r: }1 W* y6 C! B* h
这里面if(moneySpace.getObjectAt(x,y)!= null){
, X$ f9 c3 K6 K7 ~+ w8 p        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
- [9 u3 ]" m% F' l0 u+ z6 i$ [1 S( f# x      }9 T* A% U5 B* V! Z8 a
      else{3 F; R- C% c9 I- I5 y" ], @8 [, @
        I = 0;
- s) \# y! K) J' {) d9 W
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?& D5 }/ @5 T# W- p7 E* K
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-2 19:17 , Processed in 0.018277 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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