设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5422|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中# r1 c* C/ ]5 u2 `$ N, i3 O0 V
public void spreadMoney(int money){5 Z- @/ L. `8 t
    // Randomly place money in moneySpace
. i6 k8 n9 k8 p9 n1 C8 o" w    for(int i = 0; i < money; i++){
0 s1 B8 F5 C9 ~: M# b4 O& E' [. t+ @2 v: h/ P5 r' @
      // Choose coordinates) Z$ _* d& ?  f: c
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
' l( O; H, x( l. i! e2 k      int y = (int)(Math.random()*(moneySpace.getSizeY()));
" w# [! p+ p$ w& C! Q" d. |; V3 q* h8 \; [
      // Get the value of the object at those coordinates
$ S+ {, N9 ~) j: Z& g7 w% G      int I;! K$ t+ D  E4 t
      if(moneySpace.getObjectAt(x,y)!= null){7 \1 i( k4 J: [" B2 H/ k
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();" e* J/ H/ G7 C
      }; [+ Y& F' p! i% y3 j! B
      else{- E+ Y' H4 `- A" E, \
        I = 0;
2 q  K$ |4 z( d0 m* `      }$ W* F1 L1 c; {& ?
      // Replace the Integer object with another one with the new value6 i! s, p( W/ R3 P; d4 p) P
      moneySpace.putObjectAt(x,y,new Integer(I + 1));, `1 b0 h; G9 P, L- J% ?
    }
1 U; V3 K4 s* Q3 X
这里面if(moneySpace.getObjectAt(x,y)!= null){  u" R9 W+ m: c! R5 f! Z
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();; Y3 h/ a0 |9 U9 f6 Z8 E+ o
      }( K6 X  D. r6 |3 |6 W
      else{
' g6 E& A7 `- Y8 J        I = 0;
# i( v2 D0 E( F# ^( D6 ~
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?8 ?0 d7 [. P0 y* T( j* Y9 M
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-17 13:34 , Processed in 0.016176 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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