设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4247|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
* t/ L/ K0 K- t2 d( [public void spreadMoney(int money){, {/ M9 D  T/ L7 T. q
    // Randomly place money in moneySpace9 y8 C3 Y* ~; v( Y
    for(int i = 0; i < money; i++){
8 [+ [' T+ A/ v6 y( w& P8 k9 w8 Q0 Q; ?( k" v# n: l
      // Choose coordinates
/ \! t$ {# @1 Q8 U* l% W      int x = (int)(Math.random()*(moneySpace.getSizeX()));
5 b" B9 i  }6 P2 \. u3 }1 j) k      int y = (int)(Math.random()*(moneySpace.getSizeY()));
, o0 L$ f2 g5 B
9 L* W, n$ r& y3 H( h, a      // Get the value of the object at those coordinates) u1 I* |) v+ K% k: m( \
      int I;/ H3 T% X& M; f9 d# Q
      if(moneySpace.getObjectAt(x,y)!= null){
0 m5 X6 V/ }3 G  f2 ]        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();3 \5 Y  z3 X" a4 {
      }5 b. U, r4 e4 O) b  C
      else{
' f4 n  y- G0 f, P8 R' m; M        I = 0;1 v" B* I5 u. O/ N; z4 M8 }
      }
% C2 g3 |" Y0 I5 u$ p      // Replace the Integer object with another one with the new value
% d9 B! `  S. c      moneySpace.putObjectAt(x,y,new Integer(I + 1));- }2 e9 G/ x: j5 O8 M8 L
    }

% h9 f# T: |9 a/ j& I* E; |这里面if(moneySpace.getObjectAt(x,y)!= null){! D4 w  o  q1 |9 U
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();: m- d6 X8 R5 M+ ^! J7 r, l1 S9 b
      }2 m8 N6 R& `9 ]8 j7 |
      else{
0 R0 Y$ d: ~+ R: Y        I = 0;
: r0 o, d- b1 X& s1 c& C' @
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
# H# J: U. V1 g* W/ _% w初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-22 11:20 , Processed in 0.024380 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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