设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4790|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
6 n: z  E# k: W  i* L  Tpublic void spreadMoney(int money){
# S: e2 b$ R) x! ]    // Randomly place money in moneySpace
% V0 e7 W' R# K% |    for(int i = 0; i < money; i++){
0 D- k/ t7 [" L
* f  M( ^% K6 M  U9 L$ U3 n      // Choose coordinates( n8 g: x7 ?; x2 D+ O0 h
      int x = (int)(Math.random()*(moneySpace.getSizeX()));/ p3 ]; G2 S: v5 {* _; M1 }
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
; V4 m, a) }& H
! M+ z1 _5 K5 T! r, M) g- Q      // Get the value of the object at those coordinates
" f$ G. ^! S! K      int I;
4 T3 G" l' X; e' a      if(moneySpace.getObjectAt(x,y)!= null){9 {8 W0 U  g+ F! a
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
& l3 G" P+ m- a  U9 ^# G, n/ ]" h      }( i' M: z" |/ |0 A! v
      else{
% }. y5 @. K' Q- R# P# x        I = 0;* [/ F6 B5 V* R6 {7 u0 H' D
      }
3 W& Z2 {3 c+ q! q1 t! c* T+ u      // Replace the Integer object with another one with the new value3 f" x2 Y5 m& w% Z
      moneySpace.putObjectAt(x,y,new Integer(I + 1));' i+ z! d4 _* r* t
    }
9 ~- P% z3 Y; b5 a  v$ M: k6 E% \
这里面if(moneySpace.getObjectAt(x,y)!= null){
/ C& K5 i. ~! u        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();6 I/ g9 S( r1 q9 p+ |+ p
      }5 A5 u6 L5 x9 e/ O/ y) K
      else{* e; O) [0 }, j( s' V0 ^6 }
        I = 0;
. u7 k4 B' z% s3 b+ l3 K
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
8 r6 [: _: P% d4 m# t7 e( @( X初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-21 23:34 , Processed in 0.016567 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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