设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4829|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中1 F8 o8 o1 o9 F4 y) t; C
public void spreadMoney(int money){' f( g% \. X, [8 N
    // Randomly place money in moneySpace
% c, `* a8 [/ q' o# G    for(int i = 0; i < money; i++){
$ ~0 P) J0 v! |+ j7 l( z2 {3 G3 C
      // Choose coordinates; ], i$ K  j0 d" ?; I) z
      int x = (int)(Math.random()*(moneySpace.getSizeX()));5 n+ W6 V; M/ u- R( @
      int y = (int)(Math.random()*(moneySpace.getSizeY()));$ C% C# `0 |7 \/ K# N& Y* r
# {: e0 h- H/ l- S4 J
      // Get the value of the object at those coordinates
% M: S$ v) `6 m9 d      int I;! w" ~& x0 w% i3 d
      if(moneySpace.getObjectAt(x,y)!= null){- X0 B/ M* o5 r$ l( i
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
3 P; \; R, D" W2 v. r; J      }: q+ P) ~, I* d, `5 p2 u
      else{5 V# |/ R! w8 v  m' @. X
        I = 0;9 k  F- Q" }- A" u, V
      }* ^7 q- [( o" v8 Z; A5 f
      // Replace the Integer object with another one with the new value
. f6 i' E* z# e% H- T* ?      moneySpace.putObjectAt(x,y,new Integer(I + 1));
* A, v3 f: w3 s( p    }
6 O2 c( `/ Y3 ^8 s& C
这里面if(moneySpace.getObjectAt(x,y)!= null){" H- F' l9 W7 x& [9 L( T7 T
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();, Y8 b3 L8 B4 j5 s% c- _
      }1 [: w# J2 r. D3 \4 G: G
      else{1 }- ]7 s/ _3 `5 ^" a
        I = 0;

' Z) D- ~0 C/ L' d  ~" u是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
, B  y, Q' ~+ S5 e初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-3 02:36 , Processed in 0.016773 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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