设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5186|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中7 s( t1 `" @& Z1 F
public void spreadMoney(int money){2 q3 w( B) @- m
    // Randomly place money in moneySpace
  O% j1 \- w1 U0 d5 G    for(int i = 0; i < money; i++){
& ]+ [5 h( a0 }2 h) }7 p, `
+ i' b& p3 X; m, C      // Choose coordinates
( H* Y" F& \0 S8 o% S      int x = (int)(Math.random()*(moneySpace.getSizeX()));
: a, d' A( P# z- f1 }6 e      int y = (int)(Math.random()*(moneySpace.getSizeY()));( }) d% o8 M0 M+ R) [& X+ P
( m) e/ S, R3 A# H4 M
      // Get the value of the object at those coordinates
) P; z. w+ x, @$ `      int I;
* @4 q# a! U9 q* P/ ?      if(moneySpace.getObjectAt(x,y)!= null){/ ?. `! l( a0 D3 w: Y
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();# |; C$ v: w8 }7 a9 s
      }# ?* M4 W( i" }$ O8 [' B& ?3 w3 j
      else{0 |# {* _8 S) h$ B% j" }5 b
        I = 0;* ^( M6 t0 u0 O; g
      }7 S& l1 q6 A. P- P$ q
      // Replace the Integer object with another one with the new value4 ]. Q% }2 A+ B. a
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
, H8 D' a8 [4 T& G/ [    }
9 o) q: ]  N8 r+ |( `: F: K" |* s& E  C
这里面if(moneySpace.getObjectAt(x,y)!= null){
  s4 A9 f' H- y8 z$ I5 U        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
& v- F- u6 A: Z4 X      }
5 j0 g- O0 j! m  c% F6 E9 x4 t/ O      else{
6 b5 H% K# d! ?/ p        I = 0;

+ {% a$ y$ Z! p  d7 r是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?0 S/ ?% F% ], B$ }) ]
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-19 12:34 , Processed in 0.013107 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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