设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4006|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
: T" [" B5 _. j. f6 Jpublic void spreadMoney(int money){- Q5 N9 X$ q9 X" b5 }
    // Randomly place money in moneySpace
$ ~( T9 E) n' e4 Z" Q    for(int i = 0; i < money; i++){3 i" d( V9 i- Y  h" w/ _9 ^

/ ^+ f1 n$ v4 g* u; k; v      // Choose coordinates
2 D. D2 h/ a# X9 P5 Y      int x = (int)(Math.random()*(moneySpace.getSizeX()));  g' z- n/ s' f
      int y = (int)(Math.random()*(moneySpace.getSizeY()));! R6 b$ K! C$ L8 K8 D$ L) w: Y

: y- r% A' u3 u( F' P! ^      // Get the value of the object at those coordinates* d7 H% `3 `; N( E
      int I;; Q; s2 Y$ \# @2 }. y  }& c
      if(moneySpace.getObjectAt(x,y)!= null){' n- y. l: p" v3 u) j' E0 c7 Q
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
. z# I0 X' p# g- w  [. c      }& {. p5 O6 c0 K4 l* @
      else{/ o! i, }0 y' V! F
        I = 0;1 Z& [. T  K6 `3 a0 Q9 S
      }4 b/ ^6 w0 K6 r) m* S3 K
      // Replace the Integer object with another one with the new value
: y7 Z/ Y( g3 p      moneySpace.putObjectAt(x,y,new Integer(I + 1));, s! O8 X: B7 J1 {  H
    }

: M+ S; h' @, O3 u7 z这里面if(moneySpace.getObjectAt(x,y)!= null){
# I4 y. m0 B5 Y; t        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();5 e$ n' e  o- @
      }& f8 M* v" j# {* S
      else{2 J6 u, X/ m8 O0 H
        I = 0;

: ]' R; e7 `! M3 d" ]; W& r: R是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?9 ~% x7 v$ w4 @$ M7 \! m  {' Y
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-8-23 23:42 , Processed in 0.014241 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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