设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4042|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中7 m: S4 ^% P- G: P) M
public void spreadMoney(int money){* ?+ P- u9 e% k
    // Randomly place money in moneySpace8 Z& {+ B% k5 k
    for(int i = 0; i < money; i++){) u1 L* f0 T4 b  d. [
3 n% ?% F( k9 p# k7 r
      // Choose coordinates
/ E* r4 x. b, S" S- {      int x = (int)(Math.random()*(moneySpace.getSizeX()));. y. {6 c% j0 J8 A3 J3 k
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
) w$ V" W, |% w9 B4 G( Q/ n
: S8 j% [) w0 ^5 c+ O4 s2 C/ M      // Get the value of the object at those coordinates+ t& k! D4 i$ p- T: \$ ~( w
      int I;
8 X, t/ T" a* N, N8 P      if(moneySpace.getObjectAt(x,y)!= null){
6 C+ m) S7 w4 R1 n# `        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();% K/ R' j. n2 M: X* t& \
      }
. N8 T4 t# |- o/ z4 X; V      else{
* e/ |7 J+ M5 J6 P# K. o6 A        I = 0;' S- H0 _; h$ [, z' `) x
      }2 _0 g. {- I, T
      // Replace the Integer object with another one with the new value* n7 q  y1 N+ J: v, `$ D% k
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
3 x. ?1 |- ^1 |. O    }
: U6 e/ ?8 ]  t  `9 O9 P
这里面if(moneySpace.getObjectAt(x,y)!= null){
( X8 Y( p& B/ f" z& O" ^0 B        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
+ X8 [  N, ~( H' q" a' I8 q$ u      }
$ B- y( t! z7 p. \      else{
$ w4 Q8 K& a. m$ R0 V, a( b8 p4 a        I = 0;
- }8 @8 R7 u  ^; a- m* E4 C: f& q
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?- ^! F# T7 c+ n4 ~
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-5 17:43 , Processed in 0.015704 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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