设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4637|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
3 f" q) R- E* _" apublic void spreadMoney(int money){) f9 k. p5 ]4 j5 G' o& h( S
    // Randomly place money in moneySpace
( n% r  ^; g: A3 {    for(int i = 0; i < money; i++){
( n+ s) A. Z+ C/ K
* e  T5 d) s* U! r/ I0 W6 V      // Choose coordinates7 M) l2 m( p* t* J6 t2 P
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
- D6 b& E" E" Y2 L  G& g      int y = (int)(Math.random()*(moneySpace.getSizeY()));
  a0 l/ X0 M& R. J2 `/ R; j
- S6 g: D+ _+ W1 C/ X8 g2 U, D      // Get the value of the object at those coordinates, a  W; w  g# u6 G% @
      int I;) u' i5 \$ U; L. C* y: R) F
      if(moneySpace.getObjectAt(x,y)!= null){/ h% ~/ f* ?5 n, n6 L; h
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
- t# @% ]* ~0 a3 @& W) h# Y) ?      }& K  u9 P' l: N- ?6 k
      else{( l3 E6 u3 e4 B: C
        I = 0;: a$ ?5 d8 V( y/ g' g0 h2 `- ?
      }
, ]$ C" o2 m% N1 l$ N( t      // Replace the Integer object with another one with the new value
# S9 @- x5 U3 u+ b      moneySpace.putObjectAt(x,y,new Integer(I + 1));
$ `, F' [/ D+ ?4 A( _    }
: @1 h4 a  A2 ?, H
这里面if(moneySpace.getObjectAt(x,y)!= null){* C: h+ w! t4 x. p) G. @. V
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
& n% |! }1 ~2 n! P. ~      }  G" p( ?3 A# ^4 ?4 r
      else{0 ?; q" f$ A8 u, s) x& V0 T
        I = 0;
! x7 Z( S1 u& [4 P; `; Q. H
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
, O- f) ?1 |: _* h# n0 t6 {初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-5 08:26 , Processed in 0.019785 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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