设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4639|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中! O) B' {9 \/ {4 O( D" l$ [
public void spreadMoney(int money){
- Y; }4 |2 g+ N+ w% z! F    // Randomly place money in moneySpace
" n: l$ o" ^; T' M    for(int i = 0; i < money; i++){
1 {4 S: `' T  A' \# f; n) T6 _9 w. O- _% _( P. P
      // Choose coordinates, x/ U7 O# H+ y
      int x = (int)(Math.random()*(moneySpace.getSizeX()));, L- r5 ?5 D% _( Y1 X
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
; J# y( m9 C5 ?4 X. d
; Y" l' k  k1 P      // Get the value of the object at those coordinates! D& P! K  ?' P2 P3 T- B& w
      int I;. n2 f& G4 t7 K( ?3 i0 X
      if(moneySpace.getObjectAt(x,y)!= null){
9 T' I/ C  n; }9 l        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();6 q0 y6 ]2 v$ W/ N; P
      }8 ~. u3 F. `$ t4 U
      else{, `4 D1 u& y  ?0 o
        I = 0;; U  f/ D8 v! [
      }$ e9 Q" u5 v4 E5 {" S
      // Replace the Integer object with another one with the new value8 V: T# z* q9 f8 e4 Z; ?2 z8 U
      moneySpace.putObjectAt(x,y,new Integer(I + 1));* l! \9 g0 @8 Y6 `* W  ^" S% M+ t
    }
% U9 u9 A! ^& L
这里面if(moneySpace.getObjectAt(x,y)!= null){7 n9 M: f1 V$ A- E, S8 |0 ]" U) i2 ^
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();/ N( f4 H2 `, B6 {% v
      }
( G* u! l0 Z, q* F8 P      else{8 ]0 o4 _! R. B8 c9 ^/ m4 D5 S3 ~
        I = 0;

( l% D6 |- Z6 w: e, k: E1 q7 v是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
4 n4 p' x2 `5 n* A- |初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-5 09:37 , Processed in 0.014019 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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