设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5112|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
9 b1 q$ l$ k2 upublic void spreadMoney(int money){% M- V1 }/ D% F: e! m
    // Randomly place money in moneySpace
  G+ z! e3 z( H  A+ B, p    for(int i = 0; i < money; i++){$ {+ m# \) Z' s' x
0 M. f) |; [+ @" @5 X
      // Choose coordinates
% c. j2 o) M. f/ }      int x = (int)(Math.random()*(moneySpace.getSizeX()));% L! F3 G6 ^1 P
      int y = (int)(Math.random()*(moneySpace.getSizeY()));: r1 I+ f% U! }! f: ~

$ v' i% X( Z& @9 ?) l      // Get the value of the object at those coordinates7 l2 G5 m' x9 b% T
      int I;
9 s3 q2 H1 \& y' Z- l      if(moneySpace.getObjectAt(x,y)!= null){
* t( J9 `* m7 F/ K& {        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
7 i) u2 N) B1 X      }8 G" P0 [' J( F: N
      else{8 I: i& U2 D, Y' r" |
        I = 0;+ f, g4 j1 W; Y
      }1 z6 X2 w! J0 A. \) Y
      // Replace the Integer object with another one with the new value4 U+ j. i6 \" \8 [( ]" g
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
, M; x! n- i8 f! d    }

; c( J% t. _' X2 @7 G, C这里面if(moneySpace.getObjectAt(x,y)!= null){+ p7 m6 j1 G+ b) Z/ Z9 f. E
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();9 w: I( J6 S8 W% D6 _0 Z5 [  m% N
      }$ ^" i3 N- d$ i
      else{0 }$ v% }; I1 A
        I = 0;
# y4 I) V( Q2 o; A# s
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
$ ~* W( J+ S4 C8 Z0 W0 w% S初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-30 05:02 , Processed in 0.014797 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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