设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4647|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
) J2 T2 i1 j% [& Y# H7 zpublic void spreadMoney(int money){  Y. M9 ]7 Q" `* Y+ ]9 p
    // Randomly place money in moneySpace5 `, V. W- c! v
    for(int i = 0; i < money; i++){6 {% E% t, X" t) S, `  t/ h1 y

$ n$ k3 D; k. I      // Choose coordinates
. m6 s* k' X8 `% D8 n; Z1 R      int x = (int)(Math.random()*(moneySpace.getSizeX()));
3 X# K$ A! }/ M6 |4 g      int y = (int)(Math.random()*(moneySpace.getSizeY()));! `% t; b' O* K$ X' E7 R
& g2 h2 Q# }9 u  ~
      // Get the value of the object at those coordinates
1 ^7 b# N( Z: `* {      int I;
0 I4 s* p( v# y7 r$ G7 a6 ]! w! D      if(moneySpace.getObjectAt(x,y)!= null){
2 W1 I  b' J; P/ F        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();, f5 E( R( w: H# ~: K4 I8 k9 u
      }& E4 c: X& ^2 h+ W7 f, i6 \
      else{
: z' `) r4 y' j: I        I = 0;/ i, a6 ^& T6 r" f5 W& H: {. o
      }  `  ?1 l0 Z8 w" }% Q& g2 B4 K
      // Replace the Integer object with another one with the new value
1 \$ l7 Z4 D: g; i( R      moneySpace.putObjectAt(x,y,new Integer(I + 1));% N0 g- k1 u% D" M- x% D: u
    }
  d- L/ z4 M1 ]. a/ J$ w) W
这里面if(moneySpace.getObjectAt(x,y)!= null){. U( ?$ F( k5 H/ m& m
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();, F5 g6 F& c" `1 ]. k$ w2 ?2 U
      }0 z' m5 X9 C0 U! Q' b; v
      else{
' x( S5 R  g8 @1 j6 _        I = 0;
/ }- K! c6 V: V# W; p
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
# B; `; J; |$ g* f0 Q! ]$ U$ O初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-7 09:58 , Processed in 0.019103 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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