设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4371|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中5 |6 f8 A$ E$ A/ h; `
public void spreadMoney(int money){
, D. t4 S" P8 f. U    // Randomly place money in moneySpace/ V2 J" m! [( G' m" [
    for(int i = 0; i < money; i++){/ C/ K3 [- y7 m9 `2 d7 m# Z' N1 ^, {

- n, B* \, y; s/ T( d: J$ r+ L      // Choose coordinates' g4 o: B) q/ b
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
8 b' {3 Q* P; f, s, d$ o* O1 c      int y = (int)(Math.random()*(moneySpace.getSizeY()));
6 G* P! a! e( z  q  F+ m5 [9 @, c7 U
. ~, H8 b4 {1 ~6 d! ?4 P4 J      // Get the value of the object at those coordinates
$ u" f2 j7 {" Q      int I;
$ {4 W- i: k# g      if(moneySpace.getObjectAt(x,y)!= null){
2 X8 y6 r8 }* M6 i! T9 P* c        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
* |! B' h0 q0 M  G9 Z      }. S& O. f) M3 [/ R
      else{# h$ a: Y# f# X' M& R0 v
        I = 0;: E) t+ h+ q1 D7 c; T
      }, W8 l9 p! M2 _+ U2 \2 i
      // Replace the Integer object with another one with the new value
3 L7 A2 I5 a1 z" z0 {: y      moneySpace.putObjectAt(x,y,new Integer(I + 1));
) ^7 a  w! l' Y. ~    }
3 L' _! t& C9 p, [4 Z: ^  r/ m
这里面if(moneySpace.getObjectAt(x,y)!= null){4 [2 C5 C) Z+ t0 R+ t+ u
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();& ?/ u# e9 V8 q( z3 X* a8 W" K
      }
* q" C7 [* b1 J# f. \* W' B5 e2 B. w      else{1 B" c1 R6 k  \2 S4 d3 `' |! l
        I = 0;
) K4 P8 ?4 ~4 [0 a  @- A
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?* x3 S' u+ E1 x. g8 F6 i) k$ ~2 W
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-13 05:19 , Processed in 0.017099 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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