设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4662|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
) Y9 X5 C0 V6 P0 Npublic void spreadMoney(int money){
4 H6 Y. e+ c" e# Q( I- s* ]2 Q$ }    // Randomly place money in moneySpace; \% f9 L0 p- p$ G  q
    for(int i = 0; i < money; i++){
# r& m. N6 @2 d6 D. o4 d2 y/ C: u; J# W1 s1 Y
      // Choose coordinates
$ y/ V% l! m( Q      int x = (int)(Math.random()*(moneySpace.getSizeX()));1 R9 G/ R9 j; r9 J
      int y = (int)(Math.random()*(moneySpace.getSizeY()));- K& D" k+ ^' a7 ?4 m" B8 ~
) I& w( f/ n6 }
      // Get the value of the object at those coordinates
, L$ F4 J, n7 C" Z% H. M      int I;
) r' g* {) T* ]8 H2 s" u& O      if(moneySpace.getObjectAt(x,y)!= null){6 {& z! ], T4 q% v- E3 P/ g
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
4 x+ n3 {5 k. I, ^! {      }
( R& x& c3 J5 l2 y! f      else{* j. S/ U1 ~& x" g+ v( L; R
        I = 0;
9 |, e0 I* j! C7 l      }
9 L% e9 s! q- Z) E      // Replace the Integer object with another one with the new value
8 ~2 Y. c; F1 Q) K( D% u: c      moneySpace.putObjectAt(x,y,new Integer(I + 1));! c. k) w' |1 ]
    }

8 y! f! C; q: n" t/ L4 P" H这里面if(moneySpace.getObjectAt(x,y)!= null){& `4 B; [0 R, `! ?0 C) E
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();! X* Z4 r+ e" l- S: M6 E  l
      }0 h- G& v$ A& _3 a! E3 V
      else{- ~- A" Z" w2 L+ T; ~
        I = 0;

. h5 e) a# _! L3 Q  O( o4 n: Q9 y, K是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?" N; f. i' V( F2 L( C
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-9 15:27 , Processed in 0.016915 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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