设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5036|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中5 @# i8 N8 G7 v) P( z6 w
public void spreadMoney(int money){
# N' q: T/ R' g: h. V# ]3 u) K+ }- b; l    // Randomly place money in moneySpace
7 u, Y* z  t. a! I    for(int i = 0; i < money; i++){, ^" W' D' b) S+ o0 {, O1 J) k- b, ~. k
: I" B9 y- I- x; Q% E4 B0 O4 L
      // Choose coordinates5 A7 Z% \7 ~( O, h$ D
      int x = (int)(Math.random()*(moneySpace.getSizeX()));8 O5 e8 w: T1 ~9 [
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
: s8 t; q; ^% |" y- I6 G& k6 p0 ?2 {4 p9 ^+ V' k
      // Get the value of the object at those coordinates
* O  F) E4 _) e& u& |$ D      int I;; v+ l* w- U: [* |  T0 z
      if(moneySpace.getObjectAt(x,y)!= null){' @2 \; i5 V$ e, x
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
3 C  R+ Q2 b  M) q* ]      }" Q0 J6 J7 |! Z. z" ]( K1 R
      else{
! a1 r5 H* y/ p        I = 0;
4 Z* I6 x' K/ i      }
7 v0 [: C" [+ b1 L+ I3 \! k; g, f      // Replace the Integer object with another one with the new value
. }& x* V9 ^, A, K/ B      moneySpace.putObjectAt(x,y,new Integer(I + 1));
' f1 T1 E5 Z( C8 \7 v, {5 }5 H  u7 M    }
; g  V, A+ Q# D9 `$ X
这里面if(moneySpace.getObjectAt(x,y)!= null){5 y0 X0 {& z* ^* i- _9 ?/ i9 K% W
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 C6 n0 A* j  `" b4 H- Y# g
      }
0 P" o, Y2 a% }+ s- ?; V! M# R      else{8 f8 f; {$ u/ U* d
        I = 0;

/ l/ f) R- o0 o0 u; f& ~是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
' q8 b# a$ r& {4 D6 o初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-4 20:30 , Processed in 0.014855 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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