设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5268|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中; N1 ]; W" J1 m
public void spreadMoney(int money){
3 I& g; ^7 {2 i, Q' {5 v# x! Y    // Randomly place money in moneySpace* R0 W9 j2 a+ p$ D5 [8 }) A& t
    for(int i = 0; i < money; i++){( A: C. v" \* R2 C' Y& F- g4 `$ ?

5 j5 A8 V& c3 f9 F! t6 i      // Choose coordinates
5 L: c/ T4 F& K, o. e2 l      int x = (int)(Math.random()*(moneySpace.getSizeX()));
" }( l: t/ a1 t      int y = (int)(Math.random()*(moneySpace.getSizeY()));6 P# q5 L* f2 y

6 m! R% U/ C' b+ y/ h- D- W8 o      // Get the value of the object at those coordinates; T8 F1 Q& ]( \" ?% j, T8 Z
      int I;' g+ y$ {: W- ^! [$ L0 O
      if(moneySpace.getObjectAt(x,y)!= null){+ a% H$ \! q- \" Z. ?1 [- w, ~
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 \* g; ?' |4 J  J9 Y
      }
5 @4 [; u" o  n      else{0 n. v: \. ~- K
        I = 0;
1 A- A. W  q9 c      }
6 W, c+ z& l7 S8 @1 g      // Replace the Integer object with another one with the new value
" a2 I/ W# Z* `# T; c" J      moneySpace.putObjectAt(x,y,new Integer(I + 1));" x3 ~4 q; J- W8 A
    }
/ x! l  f# M8 D% E2 d  K
这里面if(moneySpace.getObjectAt(x,y)!= null){
! b& \! ]& L' |5 p# L  X        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
* b" P6 L5 d7 H/ J0 z; \0 D; v      }
3 r% m' d- Q9 \* y  x2 Q" m      else{
8 ?$ e9 s+ {: z; M4 v/ L6 S7 p        I = 0;
9 s0 U8 D4 H( {; k$ Z; E
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?& ^0 ]( w4 C4 \
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-2 13:27 , Processed in 0.023247 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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