设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5109|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中' _3 S& \) d, I) K7 B
public void spreadMoney(int money){
2 f; N5 E$ R1 u  ]2 E    // Randomly place money in moneySpace
1 W5 o6 d/ T% \' ?    for(int i = 0; i < money; i++){
" y$ }" ?5 g: U9 }1 n3 c. B
" Q' r8 x5 L, _8 [* ]# P7 ]) w      // Choose coordinates
8 Z( R) m; z, m, S7 ]      int x = (int)(Math.random()*(moneySpace.getSizeX()));
4 U5 k: D1 S1 t) m      int y = (int)(Math.random()*(moneySpace.getSizeY()));
# H8 b* O8 q6 t9 ^" I& X* _
, T8 q2 T# L8 `' {* j      // Get the value of the object at those coordinates
/ y0 @9 \  ?# Z$ d/ H$ M6 W      int I;/ T! v/ w0 R$ Q- \
      if(moneySpace.getObjectAt(x,y)!= null){
4 T* x4 _8 R# q8 }0 K  ^: R' Q8 K- f* l        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();% i7 O& V. b- K1 F3 r$ x
      }
( @% q4 F8 H9 i1 A4 K      else{
, ]" s7 f" ^. ?) y  Z        I = 0;% w2 ^  Z& w& o$ P; m8 E$ ?* o) ]8 T
      }
5 j* r; `6 u2 {6 I% E      // Replace the Integer object with another one with the new value, L- d& u# E/ Z, g  [* I
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
% c" b& c$ j2 h1 f& v) {    }

' ]6 M: a. _9 `% q" K这里面if(moneySpace.getObjectAt(x,y)!= null){) q8 J! f2 S5 k
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
( k" G! x& ]1 N$ I8 \      }$ o$ z, r; I7 L, [7 P: }& \! N
      else{
+ q$ j! V9 |  [+ M2 r( D2 R        I = 0;

" d7 k+ \: W/ \) S5 X* Q是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?$ Y% H) |4 J* Z: S- ]7 S+ T$ Q
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-30 03:15 , Processed in 0.014642 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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