设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4438|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
7 h2 u! t( r+ f/ W/ z" R) J/ Npublic void spreadMoney(int money){0 E  }& B& i+ `. t# B: e) B
    // Randomly place money in moneySpace3 N2 K. b- R# D( H
    for(int i = 0; i < money; i++){
9 N+ F: B5 k- c; v# c$ Z( Z; Q1 B1 x. d; t  r5 k0 D
      // Choose coordinates0 H: f. [1 m$ Z+ k" W- O4 V2 h7 l
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
9 H( y& }3 h4 k: g$ c      int y = (int)(Math.random()*(moneySpace.getSizeY()));
+ q, q  e$ N) _. \6 t6 M  }
, f# ?) x  D6 i6 z      // Get the value of the object at those coordinates$ }8 ~- e. y3 g0 F  h" R- A( S
      int I;
1 _* V" Y' ~5 V( @2 b7 k4 S      if(moneySpace.getObjectAt(x,y)!= null){9 G  p% ?; Q- w* V9 w
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();  N* m; H: n. Z9 A9 z
      }" ~( m3 F) v7 F* W
      else{
8 a0 n- C9 P2 e6 I7 v        I = 0;5 }4 |& ?6 i4 V2 X' P+ U  U) }
      }) R& Z5 F: h- E# j, P! W
      // Replace the Integer object with another one with the new value1 D) v- M9 x2 ~# C; N5 s7 X
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
2 ]8 r0 k0 L1 V1 x    }

! k- e8 z6 a1 @+ g这里面if(moneySpace.getObjectAt(x,y)!= null){
6 Q% K; M" _. ?        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
5 m' b( o) r) Z) N- z: `      }; M3 Y& o( P6 I# z/ J6 ~9 c! J# z0 K
      else{1 c, q# E, J- B5 p  }
        I = 0;
% P: q8 X5 Z8 z! Y+ z6 d  l
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
* j+ c. t( p2 ]4 w0 ^初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-11 00:01 , Processed in 0.021959 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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