设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4927|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中. L- E) ^# I1 _5 A8 Y/ g8 G
public void spreadMoney(int money){6 _# [! A% p; x5 D
    // Randomly place money in moneySpace
; Q. P& k9 e. J* l% x    for(int i = 0; i < money; i++){! G4 k; X$ H. ]7 F! x+ a% m

  l$ @% K' y1 ]  z' I      // Choose coordinates6 V  s& l! y8 i) z" A1 F  d6 M
      int x = (int)(Math.random()*(moneySpace.getSizeX()));% y: j0 L3 ~. S* b/ L; P
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
( k2 q+ w$ j- Q- l$ [; s  @  m( r8 B4 g
      // Get the value of the object at those coordinates
0 J0 j5 _7 x* @; T& b      int I;5 p/ v! m5 @" M" D9 I
      if(moneySpace.getObjectAt(x,y)!= null){
' K% o2 |+ n. l4 i# q! o        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();4 |1 H- b3 X6 d8 Q
      }
0 @0 Z' X# ^- Z) a; d9 L      else{! [9 h. q; O2 N8 ?
        I = 0;
7 z5 t" B: R8 d$ z0 T, j      }9 A3 `. g9 E! S
      // Replace the Integer object with another one with the new value7 B0 ^  B5 |4 C. L4 h2 S
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
* J/ Y7 W2 }8 |+ M    }
- W% J% d- [3 x1 X
这里面if(moneySpace.getObjectAt(x,y)!= null){
) G9 C1 H/ X! w& R' d& `        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
9 X$ Y2 }6 V4 p      }
' H6 W% D3 J. i( I/ a7 N1 C      else{
7 `% G, Q% e( F  ^2 s2 @9 W3 d        I = 0;

9 U/ j. ^7 \3 D/ ~0 J% t是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
6 X8 a' Z9 B9 p: k1 e初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-25 16:41 , Processed in 0.013532 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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