设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4038|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
$ h) A  d6 O/ ?* X1 qpublic void spreadMoney(int money){
. _, {8 d' C' m/ [% J    // Randomly place money in moneySpace
8 p4 P' L1 @% n    for(int i = 0; i < money; i++){
2 Q3 _& {. B. B! I3 Q  L
- s" y3 I: W5 W3 V0 p' P, V9 N& U      // Choose coordinates% g7 a; q" u6 P1 y, |2 P$ O
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
2 t( V& P8 D4 [: e! N( T, ~. H      int y = (int)(Math.random()*(moneySpace.getSizeY()));
6 W3 P8 @5 I  `/ `
% Q* o9 Q$ t3 f! n0 b  W$ ?      // Get the value of the object at those coordinates: a2 d3 q) R6 h% I' T" }. Q6 L
      int I;
% [4 V, a3 B, K6 o, j      if(moneySpace.getObjectAt(x,y)!= null){: M1 c' M8 Q8 j4 p
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
# b$ c% I% P* f, S      }) |4 m( W7 P+ S1 W5 t2 s. H, `
      else{
8 m2 s5 A8 ~# U5 w: I8 w2 {        I = 0;
, O) l( F7 c! m% c6 t1 c5 X      }
2 W# e. {1 X2 K1 {% y      // Replace the Integer object with another one with the new value
3 e- f$ H4 X" y3 R/ \( s" }$ n      moneySpace.putObjectAt(x,y,new Integer(I + 1));5 f. Q7 a: u8 E
    }
. Z1 [5 H: w' j  C: p9 y2 {& \9 ?8 @
这里面if(moneySpace.getObjectAt(x,y)!= null){8 o" n) i: L+ n- j" }+ [" n
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();, ?: k  S. W' u- z! x
      }
# ]* v1 U6 n8 ?5 E$ g      else{
9 B; S* c9 y  C1 I        I = 0;
  |/ Z( P1 i6 S+ u( u# m
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
1 X6 Q9 g4 Q# A4 _: @( D初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-5 03:23 , Processed in 0.017341 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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