设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2760|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
: e1 J9 [# z6 P+ f" y) h2 npublic void spreadMoney(int money){
$ T+ g. p  k7 Y9 R" O6 m* _  N    // Randomly place money in moneySpace
  s" a; T; {6 f% T9 k4 U    for(int i = 0; i < money; i++){
* c# \5 q2 z8 }: P9 `7 P! v: q( V! ^( R, ]  Z& f+ }
      // Choose coordinates  }' K4 J2 a5 n' A, N8 i1 \
      int x = (int)(Math.random()*(moneySpace.getSizeX()));7 Z% B4 _" J# m
      int y = (int)(Math.random()*(moneySpace.getSizeY()));. f; E% t8 X! l8 o! u) A$ Q% Q  d# c" u

5 E- P' Y! j0 k. h1 n9 t      // Get the value of the object at those coordinates! L, e" ^3 R! T7 \' x- f
      int I;5 K* J2 q6 t" [( |* T- a
      if(moneySpace.getObjectAt(x,y)!= null){, s: [0 X& ^5 k! X8 h
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
: t# w# o4 A6 y1 w) z      }, x! X, H0 M* [3 n
      else{9 V" v! u6 H7 @8 {/ h) l# X% g+ r
        I = 0;
: x, [4 C6 ~9 z$ l7 s2 `0 m      }4 Q6 p( a+ Z/ ?: t4 v
      // Replace the Integer object with another one with the new value
& M4 O, C6 }: x      moneySpace.putObjectAt(x,y,new Integer(I + 1));
# L4 P; l9 C. W- q+ p6 c    }
  j1 x' t7 g& M9 x
这里面if(moneySpace.getObjectAt(x,y)!= null){% \$ D1 T: {3 T7 ^% h
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
* s) ~/ a: D( }8 _% t2 G      }
, J- H+ [9 F7 I0 w! K      else{
- v8 x1 s$ f9 ~        I = 0;
1 m/ z4 n# L) w3 L1 @
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?- G& L; ^5 P- J! [2 F9 f
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-20 10:37 , Processed in 0.012716 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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