设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4436|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
/ e  n' T6 @% u" Fpublic void spreadMoney(int money){5 Y' \, x# }$ ~1 j0 G' ~* y8 ^
    // Randomly place money in moneySpace
# @. Y& |5 {3 ^; G    for(int i = 0; i < money; i++){$ v9 `- E) M5 H( C% ^
/ y8 M8 R" K, g! y: w' i4 n, {7 r0 K
      // Choose coordinates0 t# ?# J1 e8 a9 F
      int x = (int)(Math.random()*(moneySpace.getSizeX()));$ n" A: H- ]7 h. ^
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
$ Z# k/ p+ V* k6 _" x: Y% r
& f5 I6 o1 o; B      // Get the value of the object at those coordinates" n: G1 w1 ~4 b! v8 P7 c4 a6 T
      int I;  P; m' Z& A/ K6 l( b1 W
      if(moneySpace.getObjectAt(x,y)!= null){
: w* e& U, i, R9 _% P3 J4 m        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 @6 ~- R1 b7 L" M0 f, ?: H
      }; R! j. G0 L2 V9 K9 W0 w
      else{
" }9 G& Y+ [5 a' p1 O        I = 0;1 k. R3 U) ~5 v+ Y* N; d
      }" W4 x" Q- i/ ?  M, g6 Q
      // Replace the Integer object with another one with the new value. w- m2 J8 W* v7 U' a; y
      moneySpace.putObjectAt(x,y,new Integer(I + 1));, _; n1 e! P2 [
    }
& @+ l0 b' l, n* t7 {6 C
这里面if(moneySpace.getObjectAt(x,y)!= null){6 {' j' W) ~$ [, G
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
; k( w; r& H* v6 d+ p      }
3 R" P- o# P: x! ~/ ]) C% @' d      else{# j3 T2 d1 x) w3 j
        I = 0;
% O& f7 p" d6 z* K$ z0 [
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
5 b$ R' [9 Q3 P$ h; u* x, j9 f3 a初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-8 16:30 , Processed in 0.019479 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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