设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5384|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
* ]3 E& B7 e# S/ Fpublic void spreadMoney(int money){
' m: @: L+ M) N0 T) |    // Randomly place money in moneySpace- i5 a/ O( a3 S) X2 I# S
    for(int i = 0; i < money; i++){  S4 C+ y/ y! t3 F
# _, B2 V5 e) X6 _1 G
      // Choose coordinates
( r. k, V$ q/ R% l0 S5 r5 c      int x = (int)(Math.random()*(moneySpace.getSizeX()));
4 z0 Q7 Q0 X. J/ n  O      int y = (int)(Math.random()*(moneySpace.getSizeY()));
+ E5 B. M0 q1 |0 d
; i+ ]! c! v- p# y/ [" D      // Get the value of the object at those coordinates
3 h( i) h! f2 A! W4 h      int I;
. b* g  b. a3 E( q1 l      if(moneySpace.getObjectAt(x,y)!= null){! ^& Y# N& N" v9 L
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
9 q' c2 w- v" B  Z      }
0 w1 F. G  s9 D# W; l) j- z$ S      else{
9 r6 \5 j, }% i        I = 0;
/ V. b6 M$ o( W' B1 Q$ ]      }
" V0 e" k/ @2 V      // Replace the Integer object with another one with the new value/ M% `3 x2 g& D
      moneySpace.putObjectAt(x,y,new Integer(I + 1));3 }# n; }' ^4 ~8 S) M
    }
! L- L7 Z5 [' \. J' C4 Y
这里面if(moneySpace.getObjectAt(x,y)!= null){# T# j6 X# L* @1 n
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
! s/ L, X& }: o3 ^: P      }9 O: i) d% w; N  r# ~; V0 d% U
      else{
) D! i- c: i3 ?+ m9 Q        I = 0;

2 U+ Q& W/ T+ f是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?* v' V4 V2 V7 [% A
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-11 10:21 , Processed in 0.014496 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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