设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4529|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
+ J( i1 u* x3 T3 V( Z7 t% B% c: Lpublic void spreadMoney(int money){
6 _& `2 p3 D4 R: F# n    // Randomly place money in moneySpace6 C9 ?. y, q) N
    for(int i = 0; i < money; i++){9 r6 t9 o+ w& i4 r. \

/ W$ _0 Y) B& E5 J7 Q      // Choose coordinates
. F8 V& c, ]9 C! y: @& p      int x = (int)(Math.random()*(moneySpace.getSizeX()));
: \5 m/ K9 ~$ b: D! w) ~      int y = (int)(Math.random()*(moneySpace.getSizeY()));
$ c: P8 z: S1 D- A2 U7 s3 c4 X" I0 N" f# I4 @0 }- d7 U
      // Get the value of the object at those coordinates
- @; m  c+ u5 `8 _4 ~* y- D4 Q5 C      int I;  R# x$ t7 y& l/ K5 Z
      if(moneySpace.getObjectAt(x,y)!= null){
5 x! D( n- b2 Y/ b+ p- N        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
" E% M2 q8 [' Q/ \      }" o, q+ X! r' E" P3 g. J
      else{
+ G+ ]' ^$ ~9 |4 r* M9 L0 s        I = 0;
1 @- \* q9 T; F/ b      }
' w4 g* P) i3 p( y' C6 x* `) n3 I      // Replace the Integer object with another one with the new value  x3 Z6 H0 P* f1 o) Y
      moneySpace.putObjectAt(x,y,new Integer(I + 1));5 B& j, I$ O& @! h1 \5 M
    }
2 M0 y* s! N$ L$ E$ l
这里面if(moneySpace.getObjectAt(x,y)!= null){% W6 s/ w# O" ]7 x
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();5 a2 B  h6 W2 _7 B; L
      }
- h% L3 P. G7 N. \- _, d, H5 `      else{
4 Y# N/ @4 K5 y+ Z        I = 0;

$ _4 L" ?  a5 w" s% U' R是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
$ }. b0 w) k. \4 r: u0 g初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-30 04:25 , Processed in 0.019358 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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