设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5341|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
* h% a1 m; w. o5 ]public void spreadMoney(int money){8 l+ \8 j# \) e! e1 f$ o3 o
    // Randomly place money in moneySpace
& z3 G8 z  G, x: A( h    for(int i = 0; i < money; i++){6 v* Y, F/ f' K2 I) X( r; T8 o' y! K" W  z

' ]1 r% K( C5 q. l. ~5 W      // Choose coordinates; ?+ F, B7 }' F+ Y1 i8 V' @
      int x = (int)(Math.random()*(moneySpace.getSizeX()));! q7 v- N3 ]2 h6 Q3 B% `
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
$ N9 h' G- @# C$ J
% l9 S9 D% G7 e0 u      // Get the value of the object at those coordinates
# O0 G( p9 b+ ^) |      int I;8 C  L7 s& u+ [" T5 o5 ^
      if(moneySpace.getObjectAt(x,y)!= null){" S  J  I. T4 Y( w9 {. j, e8 W
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
+ o5 B3 v1 H  a4 H      }+ h- s8 L0 c. a; a% g/ R( n$ x
      else{% Y; ~6 u* J; _$ P& q# N
        I = 0;$ B" o8 z2 T5 V$ B1 g
      }/ s' s  M; N* r, Z
      // Replace the Integer object with another one with the new value- l; m9 @! {0 E! v+ W! x) w4 J
      moneySpace.putObjectAt(x,y,new Integer(I + 1));$ u9 m5 S4 Z& e( u$ e5 y/ e+ G# u4 C8 ?
    }
3 T& A% C2 L& ^
这里面if(moneySpace.getObjectAt(x,y)!= null){5 D" J# h7 i# m6 X  h
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
- L  C2 Q7 a) F; \  `! z: M      }
" c/ k( B5 r8 z+ a      else{, ]* z. n+ P& \+ }* j
        I = 0;

3 O! [2 S9 e, l6 s" P* g是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
) n9 Y% J% o! Y: K+ S$ }初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-28 07:55 , Processed in 0.021812 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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