设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4107|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中3 A' X2 o! \  M) i- i
public void spreadMoney(int money){
' D( G+ f" |" c0 c) A# m% L$ {( i! k/ i$ V* Z    // Randomly place money in moneySpace
, n, L! m2 H* H    for(int i = 0; i < money; i++){
$ J" R- _3 q, A& j, M% p( h" j! k+ Y. |
      // Choose coordinates  M+ t+ C, f" I! ~2 J4 P) Q( V( E& F. I
      int x = (int)(Math.random()*(moneySpace.getSizeX()));* e! p7 g+ \, G5 S- C
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
, X+ }3 Q. V7 w! K% ]
* y  ~  z$ x/ C- W  v      // Get the value of the object at those coordinates8 A" `  z( [; W+ K
      int I;
" `( M* a  ?% a! d* X7 U      if(moneySpace.getObjectAt(x,y)!= null){9 Q1 S) @/ U8 E" j7 N
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();. v5 b+ j- H6 ]: ?0 X8 Y
      }* c! X3 U& T$ I1 \
      else{
6 c  {/ x8 G* _+ y( J2 B        I = 0;
# z% z9 S$ a  I# H# L( e2 K      }
7 k0 E) b+ S& l      // Replace the Integer object with another one with the new value
* O; {3 X& d9 K+ o9 L, N1 q      moneySpace.putObjectAt(x,y,new Integer(I + 1));
( Y6 L* v. [- J& ^) t  Y6 o5 B    }

; c* N8 t1 u3 J( `: ~6 D这里面if(moneySpace.getObjectAt(x,y)!= null){
) }2 m  {" R) g8 t$ h7 F        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();* s4 V3 K, b+ `
      }
, q: X  f; g+ {7 T; _  G' W5 v      else{
# Y4 q+ Y0 [# I. f" g* g1 K        I = 0;

0 R4 a7 f# _4 R) o是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?$ U" r! S5 L/ o! \0 ]1 [7 n
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-15 11:22 , Processed in 0.013937 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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