设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3854|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
/ w8 d" F4 u3 c% i' `public void spreadMoney(int money){
% P& y- m, w& ]/ b5 X3 ^    // Randomly place money in moneySpace
- g" W; j  N: P, h& V' z8 B! ]- K3 E1 k    for(int i = 0; i < money; i++){
4 A* A3 O3 t- s& M
0 q4 R$ N9 a9 b8 w3 ]8 q7 @/ l      // Choose coordinates
% h# M1 }- R* ~# F/ F      int x = (int)(Math.random()*(moneySpace.getSizeX()));
  u  L" C! M: B3 `, T7 f% _      int y = (int)(Math.random()*(moneySpace.getSizeY()));
& v, D- x& p4 q1 W! k$ }  i! o+ w% q0 f- u8 |! {2 W) g/ H1 H" [
      // Get the value of the object at those coordinates8 K9 e( I  E$ {/ t& j
      int I;# S' J5 w' d6 m, I
      if(moneySpace.getObjectAt(x,y)!= null){
( q: r+ v* P9 O9 i( U        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();5 s) ^' x- c1 b4 A# \% [
      }3 {& n! n# D& W+ a% R( Y& h
      else{
- ]) U" b  [# R3 j4 F4 `        I = 0;
- a5 m! _/ E( {/ O      }
1 e& x5 a& P) j+ n2 c# _      // Replace the Integer object with another one with the new value
* U8 Y8 i1 E! A6 }6 _7 z. z: P      moneySpace.putObjectAt(x,y,new Integer(I + 1));# ^; S+ v# i/ A
    }

* B4 ~( |# A& \+ d3 R这里面if(moneySpace.getObjectAt(x,y)!= null){/ I7 V- ?* J7 ?: \/ g
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
- g, G0 x" q9 @" j1 S/ J4 p      }. M! C; S. [8 Z% K$ w
      else{
: x0 A: r2 F9 }; K( j6 y        I = 0;

, i/ K) \/ ]( L) H- x是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
* W5 o! q  W/ P; M, R. {5 t初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-1 08:58 , Processed in 0.012662 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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