设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5250|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中8 Q* k+ k& ^: U4 E& U! M
public void spreadMoney(int money){" x& V0 x! [! o
    // Randomly place money in moneySpace
% v9 y& H7 O6 E! I' z6 M    for(int i = 0; i < money; i++){. x2 E% N) T! J2 f( c9 G) i$ M
) G$ A! D4 J& n3 j) }% G" [
      // Choose coordinates
# y% f6 z& R7 r! ^. Y# q# u0 S      int x = (int)(Math.random()*(moneySpace.getSizeX()));: s* P3 Y3 A) i
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
  ?. y$ z* Q# T& e' j# u) M. E/ E
3 `# u$ B7 I5 `      // Get the value of the object at those coordinates
7 h* m6 _& Y2 e+ I# D      int I;
6 _+ i, I; {4 Q  T      if(moneySpace.getObjectAt(x,y)!= null){$ v* W8 f) Q, B, @2 N7 q1 ?. {" x9 h
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();* j( W* e1 [* i( b! S) ^
      }
+ D3 M& P4 M$ m      else{
! e$ [/ Z, V8 Y) k6 Q/ l1 {$ N+ h        I = 0;9 Z6 y3 v$ V4 w. r
      }) f/ E0 y, y7 ?" r8 S' r% o
      // Replace the Integer object with another one with the new value- H8 x3 E& @: j2 z  B- O0 n3 g
      moneySpace.putObjectAt(x,y,new Integer(I + 1));# a: [+ f/ Q" L1 t
    }

: F- _" `+ c5 @! ~- Y这里面if(moneySpace.getObjectAt(x,y)!= null){7 \$ M, o0 @  Z8 m( l, y9 r
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();( s7 _6 l  V" i/ U! O
      }7 e6 A8 A1 q+ t
      else{
( n# @; Y, r- R1 r/ ^0 A# R        I = 0;
( w2 @5 N, J0 w# L% \! f
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
: `$ v3 t: w2 h! U1 @! r. Q初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-1 06:00 , Processed in 0.023937 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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