设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5039|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中0 k7 \6 [# B9 B- F9 V
public void spreadMoney(int money){" y) {& T( E1 S) q/ R$ V3 _' u% h" x
    // Randomly place money in moneySpace  @. X/ u0 [7 [8 @# A2 L
    for(int i = 0; i < money; i++){; B9 ~3 u  o  t: j
% g6 R$ `0 R/ ?: I; f9 n
      // Choose coordinates2 H0 Q5 F4 p# x# ~& A
      int x = (int)(Math.random()*(moneySpace.getSizeX()));/ ~+ Y4 w/ W3 ^* w$ X& v. r0 m9 l2 {
      int y = (int)(Math.random()*(moneySpace.getSizeY()));6 L$ h4 z8 H/ V# l$ B) ^7 F
" }( `1 A! h" n0 H; Y
      // Get the value of the object at those coordinates; H. J( g$ q" R" r
      int I;
( f2 {/ X2 l. ?2 t0 T9 ^      if(moneySpace.getObjectAt(x,y)!= null){1 j4 d* N# }% G  G8 R3 A
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
9 T) Z: q# N2 _) ~      }
5 ~- J0 h+ V3 l8 H8 M      else{
. Z  k4 [# p7 l5 S        I = 0;& R# A3 w. [9 K
      }; V* r8 [2 A, n, L. v0 b9 \. C2 S. Y
      // Replace the Integer object with another one with the new value
4 l& u* r+ h& c: h0 [1 r: U      moneySpace.putObjectAt(x,y,new Integer(I + 1));0 V7 j: f9 V6 v8 F) F9 n. w) b
    }
' \  z/ y5 A$ N5 ~
这里面if(moneySpace.getObjectAt(x,y)!= null){" k9 H  C. }, o* ]8 T
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();( A+ Y% m7 i! e, ?
      }
$ v, M( C2 D' v) d8 P      else{5 A/ N, I) \* b* R$ k4 K" x
        I = 0;
+ l) w+ L9 V1 g) z
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?$ J* f9 s4 ~7 r; }7 j3 E: I* \
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-5 02:32 , Processed in 0.016494 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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