设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5431|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中/ H0 F0 M- ^; a" A7 o, v  p: w
public void spreadMoney(int money){8 U! {5 f7 a+ B' R
    // Randomly place money in moneySpace
' s, e! `( Z9 ~+ W3 n; [8 U    for(int i = 0; i < money; i++){
' t$ K' T3 o- F/ j) x
' d$ ]1 e9 o3 K  V1 D      // Choose coordinates
2 T5 N( _: c5 R9 F- o      int x = (int)(Math.random()*(moneySpace.getSizeX()));% O! b# R2 ^9 }" }2 m
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
1 \+ f! M3 L; E7 o" V8 l. A5 g1 z( `1 W8 A1 ]+ w
      // Get the value of the object at those coordinates
/ g7 n; W8 D0 N3 P* x      int I;% j6 I+ s9 _2 _; w* c) t. T
      if(moneySpace.getObjectAt(x,y)!= null){
4 Y+ a# Q" X2 F& ]7 F1 i& Y        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();, {" t2 c( n+ j
      }
4 I/ C8 A  E3 _5 n      else{
# P$ F: I; K6 |4 K+ z        I = 0;+ e( i* v# N4 p4 [& o9 I. u' M& w
      }
6 k5 Y+ x1 Z6 m      // Replace the Integer object with another one with the new value% Q& L* r  u& x+ p
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
5 I& x- t9 I! Y8 v- v( }) m    }

$ ]4 R9 \$ f3 F这里面if(moneySpace.getObjectAt(x,y)!= null){' ]' Y' {% i0 m
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
. r+ U. ~5 ?) F/ f/ Z# N0 c# I      }/ T3 \$ o6 L/ p
      else{- Y5 y) v. H  N0 X/ @0 y  e
        I = 0;

4 h! a+ w9 J( x& ^是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?" K8 B* X9 C2 j; e: x
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-18 12:42 , Processed in 0.013437 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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