设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4110|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
3 l! {  t5 p4 y! g: mpublic void spreadMoney(int money){5 M% R! f5 S  a2 U+ C+ B- m
    // Randomly place money in moneySpace& Q) w3 r# |2 \+ ]& }
    for(int i = 0; i < money; i++){
: j4 h' ^9 B) D" y4 Z) i; q4 _
  r9 u  Z$ C: ]# U* N  q* ], L      // Choose coordinates( p7 c" N  \2 k* r% ]( `9 ~
      int x = (int)(Math.random()*(moneySpace.getSizeX()));- Z3 n- T: r- s  r6 B
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
* A7 G. F6 P+ l  G
) S3 E8 ]2 v- ]0 M  h+ V      // Get the value of the object at those coordinates, K  k5 U2 h1 U4 E
      int I;
& @/ u2 C$ O( m# y# i; L      if(moneySpace.getObjectAt(x,y)!= null){
9 C, h5 v& `! K0 ^; W# r$ h        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
; O2 K  ~# F+ g$ d/ Z4 O, R9 ?7 q4 r      }
  p* z( Q! _% J( L7 @      else{
; s, W! Z. O5 Q6 t6 L5 q9 C: S        I = 0;- Y# T% a& R' O  \0 D. C: k
      }
6 I- F& ~& M* E- g" v& j0 i( g1 F      // Replace the Integer object with another one with the new value2 D. T, G3 b! k% S
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
  N0 g2 |) t# N" q    }

5 M% u  }  a+ L! z  @: E& ^这里面if(moneySpace.getObjectAt(x,y)!= null){
( V5 v( o4 t! k  ^        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
, V  x# t7 q8 Z) g) X3 P      }0 U7 W3 O' p: E
      else{3 C$ G+ }$ ]6 a
        I = 0;
: b( _/ O( w% ^2 n
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?  d" p, U% H6 h% f; _* W
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-16 17:48 , Processed in 0.015715 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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