设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4969|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中0 f& T# z! ~% e. T
public void spreadMoney(int money){! @9 S; D, `+ _+ [. d4 w4 \; b
    // Randomly place money in moneySpace0 ?& }& u  `7 Z; O( I
    for(int i = 0; i < money; i++){
7 j( ^  j+ D# K5 p
$ |0 ^- F5 h4 G$ M3 `      // Choose coordinates
% h7 `5 [6 _' m% L( j      int x = (int)(Math.random()*(moneySpace.getSizeX()));
& _: u% @8 ]( Z/ |4 [      int y = (int)(Math.random()*(moneySpace.getSizeY()));6 }/ _* g9 X! ]0 k
2 j9 c* m5 N; N/ d8 s
      // Get the value of the object at those coordinates
6 @8 U$ c" z: s      int I;
& x) r; ]* J& J/ M' L6 I/ g/ k      if(moneySpace.getObjectAt(x,y)!= null){: ^$ l( ~; k8 o5 U4 C
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
7 M0 v) S4 F# S: n      }( ~& i  U8 D; z
      else{
& U7 h; A+ w# o6 w" |% K) H: X        I = 0;
# S: U6 J( u: w* r      }% \* G; C- o+ J, H' ?5 `1 j% d
      // Replace the Integer object with another one with the new value( P5 s! E2 a  ?1 w( l
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
2 B) S2 e5 Y1 f& {- |    }
# Q7 i' ~* k) c# ~
这里面if(moneySpace.getObjectAt(x,y)!= null){4 m( q. F" Z( C! a+ H3 G) T8 r
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();) I( t! W" v) O) P1 ]9 _' q! y
      }/ N4 V) P( z9 K) N$ i& {  Z+ |
      else{
2 B8 b4 W9 K3 H: u6 \0 ]        I = 0;

* Q& I) l+ B. k8 v' B  U. g是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?( N/ Y9 E6 {; h
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-7 21:35 , Processed in 0.029864 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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