设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5321|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
2 r' E# b' H% hpublic void spreadMoney(int money){
5 K! T& C. W& O; i; f4 @9 t  d    // Randomly place money in moneySpace0 U6 h. c/ q3 R. ^
    for(int i = 0; i < money; i++){* o0 p- s. b9 D5 v+ n$ L
1 w  w% X6 u. O' Z0 K7 _3 }, M
      // Choose coordinates* B8 k9 Q" W2 V1 i) V
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
  C$ ~) a, I" [      int y = (int)(Math.random()*(moneySpace.getSizeY()));
/ ?4 m: N4 U3 j; Z$ D, \! e/ Q
! @/ }7 m2 u, T3 o! X6 f4 A, h, P% S6 T      // Get the value of the object at those coordinates
1 D8 A2 ~3 Q; v" T- A2 d      int I;
/ S9 K+ j, o$ a: q- T      if(moneySpace.getObjectAt(x,y)!= null){
0 f$ h: T% S- v  k        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
$ G  R$ |9 u+ K! s7 n$ _      }
) s/ g, x1 w# B- U      else{
5 I; S, L1 O9 ]' l        I = 0;8 D6 D( `2 W+ X6 }) x
      }* a, M! y$ _$ u+ M
      // Replace the Integer object with another one with the new value* T1 y. E: S- x- u
      moneySpace.putObjectAt(x,y,new Integer(I + 1));3 Y/ J' M% k4 H3 }. l8 Y
    }
9 t1 i0 f  B, A* H; T  \) J
这里面if(moneySpace.getObjectAt(x,y)!= null){
5 m) R- d' K! t1 h& y, v        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();  A3 w& A8 B) P  ?/ S
      }
0 A7 u9 F7 i( U1 b) ^  W      else{& g- ]$ Y; C. w+ W* d2 O
        I = 0;

3 Z" q. I- `' t, I是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
* v- E$ O! j. [# j9 \初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-16 12:36 , Processed in 0.016959 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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