设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5382|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
0 i1 M8 l0 N/ B  opublic void spreadMoney(int money){* x1 G$ l" b; G. m. [
    // Randomly place money in moneySpace8 Y! {+ m6 Q2 r1 I1 P
    for(int i = 0; i < money; i++){2 F5 s, G2 R$ t6 x- A

$ _1 v, h  C! ~& Q# C% @4 g      // Choose coordinates
( E- E) t0 R+ p. u" N      int x = (int)(Math.random()*(moneySpace.getSizeX()));
/ m& W" {2 t+ R3 F. u% W2 l      int y = (int)(Math.random()*(moneySpace.getSizeY()));
" k( U1 N9 t/ ^9 @, q$ M
  ^3 h, X2 c! u/ P' i      // Get the value of the object at those coordinates
: ?+ x# M1 \* h6 Y8 c1 c% [2 ^# l      int I;
, }! V; H/ Y0 _' j4 U) j      if(moneySpace.getObjectAt(x,y)!= null){' f/ X, m) X! P) v+ e/ N- f6 c
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();( B; o4 u% ^3 `" J
      }
6 P: [4 T2 C& ?- Q; g9 ^      else{* |/ x1 O. t8 D$ d6 F4 U: j
        I = 0;
& B; L/ ^6 R- t      }2 `3 s# h- m( ]2 Z( H& j
      // Replace the Integer object with another one with the new value
3 v- z+ `# o. p+ v, |7 Y& z      moneySpace.putObjectAt(x,y,new Integer(I + 1));
% T% f* S; b: i- s3 B. P5 X    }

) H8 o% Y5 B* e( S4 M0 q8 }" J这里面if(moneySpace.getObjectAt(x,y)!= null){
% V& t( z6 H  U" m        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
/ n) S/ h  x' T) A      }
  }1 d8 f' C( |5 D2 o      else{. X( r5 L3 x  H4 T" {0 u
        I = 0;

7 g1 S0 B$ g, @6 W& F- x4 l& o是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?) t2 b9 n9 L; K$ a6 q. C
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-11 10:00 , Processed in 0.017359 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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