设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3874|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中9 b$ z: N8 l% }! b$ q* q8 y" W
public void spreadMoney(int money){
- b7 {1 u% P2 `+ @2 W+ \0 I    // Randomly place money in moneySpace
+ j+ Y: r0 k# D( ?0 p; ~    for(int i = 0; i < money; i++){2 i3 k6 ]. g6 ?; ^8 e  Q, G

1 U5 E3 |8 Z7 X- L; s# z      // Choose coordinates
4 s+ V" Q/ e6 J* e& h3 E# S6 ?      int x = (int)(Math.random()*(moneySpace.getSizeX()));
# z( g+ _3 n% Y% `, c5 n* A      int y = (int)(Math.random()*(moneySpace.getSizeY()));1 t5 ~& Q# _; \3 p" L: B6 x
2 v) ]0 C2 F4 m5 ^9 [
      // Get the value of the object at those coordinates$ e: |. ?) h  h! H, p) R' }
      int I;
# u$ ^- K% c, \      if(moneySpace.getObjectAt(x,y)!= null){3 X. V! S; R/ t' ]
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
8 c& y0 M& L9 n/ `. f& g. q      }( }/ Q2 t4 a, t8 {# R- b( \
      else{% N9 @. f' Y; C2 R
        I = 0;
3 m7 o# J9 J9 ]% l9 E9 v4 y      }
& {9 ]6 k; W) g: G# b5 ~% }  H      // Replace the Integer object with another one with the new value
7 x* X/ k! z8 ?2 C      moneySpace.putObjectAt(x,y,new Integer(I + 1));5 j# j) }: d( a# C. {  r
    }
2 [# H  C+ W4 u, j, e& e
这里面if(moneySpace.getObjectAt(x,y)!= null){
5 Z3 ?" @: E, O/ W5 X        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();9 c" t" D3 E" b. ~
      }* `" `6 {, v: f: \0 o- L: S: B
      else{7 C' m; P' Q) A
        I = 0;

5 L! s8 Q+ z# ?# T7 m1 X; y3 N是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?" D+ I8 }5 J* \8 u' @  b; x
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-6 22:50 , Processed in 0.012752 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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