设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3855|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中1 V1 z2 x+ J9 w7 N" w1 ^  \
public void spreadMoney(int money){
; g( W. g7 J% c* y1 S* _    // Randomly place money in moneySpace8 u# X: d$ j7 B- c. K2 E& M. d
    for(int i = 0; i < money; i++){! o  F9 e  `# m8 T. M2 G5 S3 w

, b- b  M& O- O+ J# b+ Z, ^      // Choose coordinates
. a; q# V$ c8 q" I& Y# U: d      int x = (int)(Math.random()*(moneySpace.getSizeX()));
4 [! X1 X2 D8 [% M" l      int y = (int)(Math.random()*(moneySpace.getSizeY()));
9 A3 g2 Z8 ~8 _# x+ E: E+ ]; G8 V* Q: p" e" l2 P
      // Get the value of the object at those coordinates) O' d/ C2 O! G) q2 d0 M8 O6 @" x6 r
      int I;% G, `' G" F& L: p
      if(moneySpace.getObjectAt(x,y)!= null){
9 t: F$ c: W- p3 p- X' |        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
& y. ^; h# K, A! \+ ^2 s0 k- X- S      }& |1 v: x4 s% c( W/ [6 p
      else{8 e& L4 h2 r; p$ `/ U0 C
        I = 0;# T, n8 c* c# r3 M
      }/ Z: F/ l2 S2 p
      // Replace the Integer object with another one with the new value9 G2 K2 D2 u- O
      moneySpace.putObjectAt(x,y,new Integer(I + 1));0 F( {2 k- U9 K, k
    }

  q# b3 v& h& U0 }. p, I1 p  {这里面if(moneySpace.getObjectAt(x,y)!= null){
0 R6 K  C+ Q: d; |! a# Y        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
$ _1 U. l% s1 l" y: h      }
9 L& b5 ]: a' F7 ?2 K9 ~& A* v# u      else{6 k& a, g5 g) z+ v' I! S9 K
        I = 0;

* u( d* S4 P6 @; O+ p4 _是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
0 Z& E. V6 G6 i3 \# v$ J初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-1 13:50 , Processed in 0.015502 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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