设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3875|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中9 G9 e% A, i8 _9 Q$ `
public void spreadMoney(int money){2 v' s  g) x3 k$ ?0 y0 P; r( b: [
    // Randomly place money in moneySpace
$ j5 q4 C6 Z  V0 v) V    for(int i = 0; i < money; i++){9 H$ q0 \' x, F* I( L' {) }- v

# r. X3 i9 Y7 J      // Choose coordinates
. o, N' h7 v5 s. Y. `% S1 k      int x = (int)(Math.random()*(moneySpace.getSizeX()));
6 l8 t, c/ R9 N6 d      int y = (int)(Math.random()*(moneySpace.getSizeY()));8 g! {: m8 k0 D! R% f3 L. c- d# r

7 L' O5 ~  g( v( X" K5 `7 [      // Get the value of the object at those coordinates
+ z  M8 J' X' Q/ F/ u* _6 Z+ P% ~      int I;
( N2 G6 K+ R; v; K" f6 E      if(moneySpace.getObjectAt(x,y)!= null){
8 c$ C* O6 g( Y- A; _        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
0 a* ?$ v& Z7 f& E5 L+ Y' R      }+ ]7 v# l* H" s% D3 H: @
      else{1 q- M; j3 [, J, r0 ]1 {
        I = 0;& r$ J' Q' X, k0 {; o
      }
, ?# y+ D/ z' z" T; F0 A      // Replace the Integer object with another one with the new value
8 r/ q/ y' E" D% m1 W      moneySpace.putObjectAt(x,y,new Integer(I + 1));  L7 i1 d( b2 Z  v2 R
    }

3 ^9 l% W& Q- }$ b. p这里面if(moneySpace.getObjectAt(x,y)!= null){
" S: x4 f: @! ]+ z6 V6 n2 K8 C        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
- b5 T5 b+ [) h  j: I% t# b+ X      }
5 u) ]: v5 N% G8 K! A9 Y% Z      else{
# Y/ c$ D0 g' T" R        I = 0;
/ U1 O4 d' q4 P. G( }
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
9 p, s: d+ |8 U1 ^' g初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-6 23:18 , Processed in 0.014751 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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