设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4121|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中& z  |$ X2 l- i4 l0 m
public void spreadMoney(int money){
& S6 v* u6 C' \8 y, R( ^    // Randomly place money in moneySpace4 i+ {$ E6 Q8 \- g5 p9 p2 g' {; T
    for(int i = 0; i < money; i++){$ c* T. m: F: \8 m
: ^, D  I' S  p( [, o/ {% i) a$ S2 d
      // Choose coordinates( D1 F- p: F. g1 F# P) O
      int x = (int)(Math.random()*(moneySpace.getSizeX()));3 O0 M" }% c5 {9 _
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
: K- S- o3 R) ~1 w8 H1 u3 {( O* K+ h# T
      // Get the value of the object at those coordinates% G) b7 I. t2 C! \, M3 }! |* `3 |
      int I;
6 c: i4 V+ |$ ?1 T      if(moneySpace.getObjectAt(x,y)!= null){$ [- s2 c: a" g" J0 D6 m5 N
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();  S3 n* }) @3 h  _
      }
8 V- I- A+ r9 h+ ^4 ?      else{
+ s& A! h/ i7 V2 J$ m" f; L* m        I = 0;- ?/ p9 N: {% C3 p7 O" q
      }
6 I% y8 r* m* N5 |- y      // Replace the Integer object with another one with the new value4 _% B9 V+ k, f2 b
      moneySpace.putObjectAt(x,y,new Integer(I + 1));. g; v2 f1 G5 p
    }

: C* a& t0 W3 p# j. w2 [这里面if(moneySpace.getObjectAt(x,y)!= null){( J& u# U2 @0 r% ?5 t; I8 p$ x
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();$ k- U" G; _7 O0 |
      }
6 ]: _! h2 C- b% O: @4 L7 U      else{/ P; l) k- D9 Z! y; E
        I = 0;

, y8 O# e2 {" r. B  O是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?# H8 }* d' V* V# ?# i% g. [
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-18 14:49 , Processed in 0.015213 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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