设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4337|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
; B; S* ?9 P4 p8 Spublic void spreadMoney(int money){
- B9 O1 F9 M0 o" U1 ^& V% y    // Randomly place money in moneySpace" f( L' [$ D6 r
    for(int i = 0; i < money; i++){; e' z3 R* N9 I+ l

- V) E% d6 v! `! ~! c+ s      // Choose coordinates
- g4 e; V$ b$ K- o5 ~; M      int x = (int)(Math.random()*(moneySpace.getSizeX()));, Q/ ]1 y# l$ T( x$ h
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
+ s0 V" J- ^& l) h* c+ S' h; D  X
- H5 q# y8 l0 n* d6 k0 e1 n) G3 z2 H      // Get the value of the object at those coordinates) F& ^$ g$ e9 X) E' Y$ d
      int I;  ?  C3 z* J( u, @, F" B
      if(moneySpace.getObjectAt(x,y)!= null){: n0 y) s  U# l+ @
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();' u3 }1 _" ~. R4 ^$ z6 B
      }& }2 W5 u9 z& |; f. D. A
      else{
! N% f1 [! g) F9 v        I = 0;
& c4 N4 ^* Z) v3 V* @, t      }, s; ~8 a- `: p9 k: o3 Z* ]
      // Replace the Integer object with another one with the new value
1 G( Q& B0 c1 y) n      moneySpace.putObjectAt(x,y,new Integer(I + 1));  P7 G' k' r3 v/ N# H# p7 `& D$ p
    }
" U. J6 v0 S/ z9 \6 }( ~- r  l
这里面if(moneySpace.getObjectAt(x,y)!= null){
5 s/ M6 p3 A$ e        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
# ^- D* ?8 c+ |1 M- f9 F4 f: A      }
0 [' G% P+ F0 n. J      else{
- u3 l5 Z" Z  \8 K# K7 [/ y        I = 0;

; S/ t! B; n8 _' ?" ^# B3 o+ C, u是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
/ x) E6 ~5 O, ~9 ~初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-8 22:21 , Processed in 0.021262 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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