设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4748|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中7 b9 o3 h# X* G% {( n
public void spreadMoney(int money){
; G$ j) I' F$ T: k    // Randomly place money in moneySpace
8 i! `5 V3 x: {3 _( t5 Q6 m    for(int i = 0; i < money; i++){( e  B$ y$ k/ ?

% K$ Z4 d/ z4 y6 K% Z      // Choose coordinates
7 p! h- y- P( X% x3 r! F      int x = (int)(Math.random()*(moneySpace.getSizeX()));/ m* L3 k2 z. L% T
      int y = (int)(Math.random()*(moneySpace.getSizeY()));1 c5 |5 t  ~) |
; v2 K+ ~  s' _
      // Get the value of the object at those coordinates
! B% M9 {3 w$ s; D) s) r, V# K) x6 Y      int I;* h+ K- g* J* v& j* e( k- v: R
      if(moneySpace.getObjectAt(x,y)!= null){
8 g9 g* P2 j1 G7 s, [5 b        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();5 {' H6 Q' v+ l
      }
2 r9 |8 @' M0 Z1 D1 \. p/ B6 g3 j! |      else{
: k6 A6 W5 _$ j: }4 D, g+ H        I = 0;: B  g7 k" c- `
      }, x6 e/ W0 M  ]  T, J
      // Replace the Integer object with another one with the new value
$ E& g1 ^* \* d( s' p- J# u! E      moneySpace.putObjectAt(x,y,new Integer(I + 1));2 D" D/ Q1 y. f3 k
    }

" c" ^' ]0 R  T7 G这里面if(moneySpace.getObjectAt(x,y)!= null){
. D+ r4 E3 t3 T0 V* A! h        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
$ W$ d8 F: G: ?3 j      }2 O0 Q/ ^* ]+ a2 T$ o$ s
      else{
7 L' @, g7 g! D( m: r6 f& C        I = 0;
: B% U/ \3 [0 V3 f
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
, ]- x; O! O8 ~" h$ Q, {3 U初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-9 13:38 , Processed in 0.017615 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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