设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4775|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
" b& @; Y, D" Cpublic void spreadMoney(int money){* o( y5 v& g3 O- ?
    // Randomly place money in moneySpace1 a4 V3 i! e/ k" M9 L; p
    for(int i = 0; i < money; i++){" x0 @" b. z- c# B

! |: {5 V/ _" O      // Choose coordinates" S4 _; _- s! T  n) I' W9 j
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
$ O7 I3 V3 g& K/ g% d      int y = (int)(Math.random()*(moneySpace.getSizeY()));
& `1 U! O. V( a6 G% H
2 Q7 Y* T) o/ O# Q" E" L      // Get the value of the object at those coordinates
1 j& P1 ^$ P# M) Z. V( P      int I;
/ G# C) L& j" |, u7 `, E$ k0 t6 O      if(moneySpace.getObjectAt(x,y)!= null){
5 b6 J; V6 W2 r2 [1 B% m        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();! R5 N/ b/ \+ |
      }& X2 g( W$ C/ o9 R, D
      else{
6 \& u5 b( e& ]% I        I = 0;( a) B5 z% j0 `  l
      }
. a- o, W+ j/ q8 ^7 q6 u5 \      // Replace the Integer object with another one with the new value/ M0 h3 V  ~; M$ a0 p8 I4 _; J
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
3 ]4 D0 U, }/ W. Z    }

. ~6 _! C) B+ S' M这里面if(moneySpace.getObjectAt(x,y)!= null){7 O+ v% L% {- j5 q
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
' U$ [8 m$ k6 d+ ^. V! {2 @      }
( q' `5 i8 y" t; H! {( t      else{
3 l: K% r) P, u. h, k1 m        I = 0;
- l- b9 S( \( i3 z2 }* ~' B& Y
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
( f/ D- q$ h6 x8 X8 M8 z初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-18 05:44 , Processed in 0.016065 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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