设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5130|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
1 X0 k% m1 N7 ?" Bpublic void spreadMoney(int money){
$ L# _, }4 A, f  n    // Randomly place money in moneySpace8 K/ W& ]1 d" {2 D: Q/ U) e, G! q
    for(int i = 0; i < money; i++){" e/ t& Z4 m  Q! h% a; z0 D

( j$ p" N  E3 Q2 P( ~& n0 q      // Choose coordinates; i2 Z. l/ y6 G  h
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
( P: N. m1 v* I      int y = (int)(Math.random()*(moneySpace.getSizeY()));
1 \0 X4 {  E: P
" o0 B* \+ |' V+ I0 [8 F& o# G+ L+ B      // Get the value of the object at those coordinates
  }" {5 K7 m( X9 j2 w/ Q" P$ P; t      int I;
: H* K" l* F; R9 t. M4 P; o      if(moneySpace.getObjectAt(x,y)!= null){) S, ^2 P1 `) d! S$ C! Z
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();& b( d  Z3 S* h  t- W  b
      }" M$ L6 c/ ?: q* J0 p. w
      else{8 X+ w7 V' x, q; A9 J( V& B
        I = 0;
' J$ }' P) g7 z9 X+ B: x      }; G  G2 V+ o  `* K( e
      // Replace the Integer object with another one with the new value/ U8 V8 t( _7 q2 J5 u
      moneySpace.putObjectAt(x,y,new Integer(I + 1));: v7 m, W8 w5 H; R, l# w, J" \
    }
( e2 f% z4 ~9 J3 e% A
这里面if(moneySpace.getObjectAt(x,y)!= null){; d$ a+ k& M9 C2 ~7 t
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
5 P6 p$ H. Y3 T9 p& ^      }2 M3 M, T" M! _4 q+ X
      else{3 P2 b1 V2 y9 q5 O, A
        I = 0;

- s# i4 M1 n( T' N+ W. F是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?+ Z6 \2 o5 {, k% g
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-9 18:07 , Processed in 0.012041 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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