设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2782|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中/ m1 Q# q$ }% S* G& r9 g
public void spreadMoney(int money){
0 I( Q8 i2 J( o- C3 ^( q. O    // Randomly place money in moneySpace
& Z- i% k7 C6 ^' u    for(int i = 0; i < money; i++){
  B! _8 y7 L2 L+ w  Q1 |( Y+ a6 Y$ u+ z# k, y8 |4 i
      // Choose coordinates1 }7 c% r& q4 q- H2 t/ `2 g! j
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
! v# p* `- k( d* j$ ~3 t, y/ E      int y = (int)(Math.random()*(moneySpace.getSizeY()));
/ u0 M- x( L; S4 B. [9 B! V4 t  x2 h- n, L2 I: p9 ]8 a
      // Get the value of the object at those coordinates
' e, s9 ^" P. i! ~      int I;
8 s+ c9 h+ `" M      if(moneySpace.getObjectAt(x,y)!= null){
$ e! Y: J) X6 X" _7 v2 V        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();6 @3 p# Y+ q0 J7 I
      }4 i3 \7 [5 P' P' t( U, m* v- D$ r
      else{
0 f6 V* L, m& s        I = 0;
7 i6 w1 q2 `# u2 k( C- Y: b9 q6 f      }  s  ~) D% Q* T/ J( _
      // Replace the Integer object with another one with the new value
5 B; b: y8 d/ K8 K- ]      moneySpace.putObjectAt(x,y,new Integer(I + 1));4 u3 M! M! l9 [( f- W  P
    }
. [  J  y" e7 L! F! d
这里面if(moneySpace.getObjectAt(x,y)!= null){
( Z1 m$ t: {, B7 a: p1 L/ L        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();. H* ]  t% h6 r6 N* s
      }2 Y1 \1 e" h' E/ }, r
      else{
# G1 S. z& G" s' {; v" t( }" f        I = 0;
& c$ S! P6 O% J1 l- [
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?5 W8 C2 l! {" e$ I3 g9 }8 ^$ [3 L* v4 g3 O
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-6-18 01:26 , Processed in 0.013108 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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