设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3872|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中% i) {* n- I7 ^' U
public void spreadMoney(int money){
# `. k8 ~+ \  F$ b+ E& p    // Randomly place money in moneySpace' Y  Z, I! H* U: e! R' [1 _; S2 I8 d, d
    for(int i = 0; i < money; i++){% i  y7 R9 U6 w# _0 `( S$ m

! X0 K7 X7 m/ ?& |0 L      // Choose coordinates
. O+ c* j6 k' l+ e8 U1 o! ?; t( O      int x = (int)(Math.random()*(moneySpace.getSizeX()));+ j6 l0 ~: ^4 {' X' p8 o9 p  S
      int y = (int)(Math.random()*(moneySpace.getSizeY()));6 S* O2 \- w( j1 q: ~

! q" |2 L' ]1 i7 G      // Get the value of the object at those coordinates
8 W' i3 x1 A1 ?7 R) ~      int I;' r, A4 {' S0 j6 L
      if(moneySpace.getObjectAt(x,y)!= null){
9 @+ `$ [4 y' D0 J# J- L) s/ U( R        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
% S. A5 l+ L, M7 V0 q: }      }' O/ ]6 r6 V- [; @2 K8 h+ P
      else{2 s" ]0 P; v9 c$ t) M7 n- e
        I = 0;2 z% Y# x1 [* W! r" G
      }
0 Y8 Y  X! l$ q      // Replace the Integer object with another one with the new value- f) ~9 T" u  E% e
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
4 \3 D, Y! o- w, U; X! z    }

8 c, F' ]& L8 W# M这里面if(moneySpace.getObjectAt(x,y)!= null){& }0 B/ Q( o! ?! _; e
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();* F6 V2 O6 o/ n$ w  a# }. Y. u! O
      }
7 Q3 ~8 b) R2 N& Z0 q6 @8 O2 A      else{
( E0 ^( @' D$ l% _' v' a        I = 0;

% p0 K8 Q0 @8 S* h% k7 l9 U是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
0 w% A8 s. G$ m; @初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-6 20:24 , Processed in 0.015122 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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