设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3869|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
& c" I$ e- }+ G! ~1 Kpublic void spreadMoney(int money){5 e' G" O& n6 R+ j
    // Randomly place money in moneySpace5 J2 \) t2 b8 A4 N4 W( V5 a
    for(int i = 0; i < money; i++){
. p9 i1 Y3 c. g8 Z* U
7 v2 L$ s/ Z, D8 E) o' {      // Choose coordinates/ W/ Y: P7 I! z
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
7 _6 t# b: V! B2 z7 }, B+ f      int y = (int)(Math.random()*(moneySpace.getSizeY()));
) R* `" u  e; y2 H7 |/ `
* h& F1 m9 O" P      // Get the value of the object at those coordinates
5 @1 {- m$ a8 `, @      int I;' j' j% d/ K! V
      if(moneySpace.getObjectAt(x,y)!= null){: L( z: y' h. G1 M
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();8 V; `; H. `, n. T3 }% s
      }
! R8 {0 M% s8 D      else{& v3 C: ^* h: D' [6 N8 @# ~
        I = 0;  R( r& y+ Z( a
      }+ n4 D! _$ x( g& _7 ]( d
      // Replace the Integer object with another one with the new value( M. A+ n7 |" V$ U, ]( ^: C6 _
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
/ m; r: e2 g) t7 U6 ?  T! }4 E    }
5 M+ }' Y( S4 X0 }$ V
这里面if(moneySpace.getObjectAt(x,y)!= null){
& K3 A$ o# ^$ K: @! l6 g        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
7 t& B$ ~0 Q* n( f, M2 _      }% H5 k* \8 E$ o* q; E# t
      else{
6 r( V2 Y% U! C2 c        I = 0;
) a$ Q# A- C' K8 X, O, {. _
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?8 `2 R( {  y. o, M9 }5 `
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-6 06:45 , Processed in 0.019370 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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