设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4482|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中0 ]+ t; q: u9 f3 u
public void spreadMoney(int money){
9 b& K' N5 `* d2 h. ^    // Randomly place money in moneySpace
/ z0 ^" d: G% B' Y, Z    for(int i = 0; i < money; i++){
' _, o7 ?3 V2 I% v' Z9 N* m
2 ]1 }3 ], o( i4 n+ O, q+ A# c      // Choose coordinates4 c; g% `7 H! _$ |9 V  w4 [
      int x = (int)(Math.random()*(moneySpace.getSizeX()));) @+ o( P6 v5 b* w' n
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
& L0 Q; q. a1 h+ O
, V  L" g9 Q& i" f# t      // Get the value of the object at those coordinates5 }7 S- s. ?! a" A$ n  m8 i* X( {
      int I;
8 |: i$ p/ J( K( U' ~      if(moneySpace.getObjectAt(x,y)!= null){
( n# a, }5 s/ L2 L3 N0 @% D        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();) ]& u4 D7 W, Q* I9 Q) t
      }
# Y3 g" w. O. f( A& X      else{
( o+ t4 i" h9 X9 `3 u        I = 0;
$ F9 q! N1 D1 m/ M4 |      }5 Q) Q; r4 V# P5 W
      // Replace the Integer object with another one with the new value5 @% S; P9 x9 C, H& `  y, i
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
* M2 i  v2 y& d! `9 K    }

, F* a" `; x$ M5 T2 O- R9 j这里面if(moneySpace.getObjectAt(x,y)!= null){( z7 @4 n1 k0 u9 w+ `9 t
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
0 L7 _: C: ]5 U( ^/ p; x2 i      }5 d9 {# t) }8 L$ e
      else{& Y. A- b1 t+ B
        I = 0;

! h% t* a+ x! l- y! C是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?5 l/ V& a# A* q, v3 m
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-17 01:50 , Processed in 0.019683 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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