设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4530|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中' Z( \% v8 e6 ]
public void spreadMoney(int money){, ^& Y& v! ~, W& ?; l( X' \& ?
    // Randomly place money in moneySpace
: g; z$ ^2 q$ p; x, ~/ e9 E0 s' U) n    for(int i = 0; i < money; i++){
3 w: n8 t: Q5 P# x$ p' N" {% q! S# M/ [8 @. [
      // Choose coordinates
: o9 V. b5 I; X/ b8 T, l2 \1 ^      int x = (int)(Math.random()*(moneySpace.getSizeX()));+ d% r+ O; o# I4 t  Y* E- m6 |
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
) e4 ?) d6 ?7 ?/ R; D
. h1 g% j2 ~3 o      // Get the value of the object at those coordinates; B, A4 }6 t" c% e6 U
      int I;
/ \- g" Y9 {7 o' R0 c4 G- _5 m      if(moneySpace.getObjectAt(x,y)!= null){
9 x6 n& K/ o9 w0 l4 t5 m) F        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();; O' O; B7 C: y9 ]
      }
: g! X0 N( G9 ~8 B8 T      else{
& i- e- p7 `7 I5 s, G: Q# D        I = 0;) A. ~( c) J0 V
      }
* k6 F+ r9 J2 P6 {; i+ Y6 e" `      // Replace the Integer object with another one with the new value9 D, f6 E4 A$ B- p4 G! r
      moneySpace.putObjectAt(x,y,new Integer(I + 1));; N! g& q% q" B( o' q3 s6 X
    }

& {/ r8 Z( l- L* s$ Y& L这里面if(moneySpace.getObjectAt(x,y)!= null){
# J9 @  u( H) i* ?" o6 N/ X) O! a: N        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();! A& d; A! B3 a
      }
( x  k1 e6 E8 ]6 v! [+ K      else{
- C& `6 z. W$ U; C4 c3 i        I = 0;

) w8 E: W4 M& k; }" Y' a+ P- J是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?2 X& q, o) r5 w; o  O6 s5 x
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-30 07:05 , Processed in 0.016778 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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