设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5316|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中$ ]. h3 s  L3 p8 g, a
public void spreadMoney(int money){
# T) B, U' u! x5 Y9 m2 M- }# q# l    // Randomly place money in moneySpace, [8 ^: x8 x% @1 t/ @( v; v
    for(int i = 0; i < money; i++){
( ]+ I+ o6 u7 \, Z$ @  ?* ?0 Q8 ^# v' M8 L) M# I$ T2 s
      // Choose coordinates" _: A! C: I4 C3 ^9 P
      int x = (int)(Math.random()*(moneySpace.getSizeX()));) B- ]* \/ E: H$ x( p. R
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
! n. |9 Y# u6 ^2 @4 w3 j3 |9 a1 A* N: a
      // Get the value of the object at those coordinates7 O. [4 ~8 M5 R4 ^6 b
      int I;% O; d/ w. a0 G6 h8 ]3 b
      if(moneySpace.getObjectAt(x,y)!= null){" Z4 G3 ~5 |4 s( U% H. p. `: D
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();) n+ q* V, p1 l* r% D8 J! u$ F
      }# h; L. M- ]. L9 G+ A1 B" p
      else{8 ?) S' o/ w1 C2 B* z& `! o1 `; w
        I = 0;
8 `, T' b! Y$ A$ R. v; F- O      }
% l3 o8 Q/ n- h  t: F$ q5 s      // Replace the Integer object with another one with the new value
% H& V& X+ e5 r* f      moneySpace.putObjectAt(x,y,new Integer(I + 1));& u! G2 F0 C3 w6 W. C* H2 t
    }

* d- X! H  M2 M  J1 _这里面if(moneySpace.getObjectAt(x,y)!= null){' X4 Z1 b: |1 |% E. n, p
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();7 C5 k. q0 b; l' |! T% Y0 G' I4 S4 J, `
      }
9 S$ R$ e) h6 R8 _      else{
( S' R7 k; B( b* K% u        I = 0;

* r. n. ]/ i. ^9 p1 a是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
+ i/ b* d6 R# \- A" J) T初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-15 06:14 , Processed in 0.020861 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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