设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4527|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
0 a  \# _! ^' r4 o: Y& W* Gpublic void spreadMoney(int money){0 J3 N" n8 c9 q9 a0 W# {$ D, x+ y
    // Randomly place money in moneySpace2 w; o9 [; C* [, @, U# Z) e
    for(int i = 0; i < money; i++){
0 r5 h, A% J8 V  W* e1 B) c
2 Z+ u  f! J6 k6 y      // Choose coordinates
5 b) L, {3 V/ N) W      int x = (int)(Math.random()*(moneySpace.getSizeX()));% J2 Y' a) v9 D
      int y = (int)(Math.random()*(moneySpace.getSizeY()));7 i4 T+ L& P$ T3 E; D$ y9 M; b9 q9 V

7 ?7 g0 [: o) ~+ R% o! T1 k% s      // Get the value of the object at those coordinates
5 S) Q' y2 K3 f# G% b      int I;
$ r' d& i% {! [& G* g! N% u      if(moneySpace.getObjectAt(x,y)!= null){
; B8 w) e5 g! s5 ?' k1 O        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();: d# ^" Z0 {* d( p: z5 l
      }* q( Q" R, ~% C' ]" J3 L
      else{
  A+ ^' ?7 ?7 W0 q; u: L        I = 0;
  t& h' g1 A' F- w7 k* u+ n1 R      }
) q' ]" j. f2 n6 x      // Replace the Integer object with another one with the new value/ p8 j" @2 l* h9 x2 A4 s
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
% n8 @2 b9 ?/ K* K1 Q  s" i    }

/ E; e9 t7 `& |' O* [这里面if(moneySpace.getObjectAt(x,y)!= null){
: F- N' i% G) d$ O0 U  O( @, n. m        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();; d6 e1 b* u- P( J9 L4 G3 M4 ?
      }
* ^# M, I7 h; y- V" E& o      else{2 l6 m; C3 o, W% R% V' `
        I = 0;
: _$ ^" B7 n' k5 e* W. J
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?4 r0 q" ^( U! {/ R% }$ I4 t# j
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-29 11:45 , Processed in 0.014182 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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