设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3862|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
- x0 ^( w1 M" J$ I' ^public void spreadMoney(int money){
# Q8 c( [0 u# H+ @9 I2 s4 I1 `    // Randomly place money in moneySpace9 e1 n/ t. M( K' b/ @* x
    for(int i = 0; i < money; i++){0 o8 b4 H% G9 U' i) T: p0 n  `; g
  Z: C! i$ f, G2 g, ]/ E
      // Choose coordinates1 [/ ^2 x, d8 o3 A" Q! x, P
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
9 [7 E' y% v0 s      int y = (int)(Math.random()*(moneySpace.getSizeY()));
* Y2 v' r" w* Q% m( k- `4 ~( v1 W; ^7 Q- M4 ?5 y
      // Get the value of the object at those coordinates  Z. _. V' t* u5 Y' C5 y6 H
      int I;
: F- L, o$ }. S$ [+ b1 Z% Z      if(moneySpace.getObjectAt(x,y)!= null){
- |4 W3 Q0 y3 V& [9 ~        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
7 \( z/ D( ]1 M. d      }
/ {) R9 M. Z# w! Y" H7 ~% i4 C      else{
; `$ p2 P. ]. e        I = 0;
, q3 o0 Q+ B4 v6 W( y+ h; m; d" G2 g      }
! L+ @4 J! a: K% z2 \  c      // Replace the Integer object with another one with the new value2 ~. Y; i  X6 q4 p8 B
      moneySpace.putObjectAt(x,y,new Integer(I + 1));$ D4 R" V, s% M, L
    }
! {" ?2 y1 d" }
这里面if(moneySpace.getObjectAt(x,y)!= null){
; J/ K2 Y9 |8 n; C" u( E. {; B2 l        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
8 ~0 a! J7 b6 p9 l! B      }& q" f) x; ~6 ?/ V2 Q  i) A* S
      else{- |& C* u, D! R/ N' d, Q9 z' [
        I = 0;

9 x8 R. a: Q7 ?$ T是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
4 `$ \; W5 J; ~8 h5 ?. r初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-3 15:30 , Processed in 0.013488 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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