设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5111|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中" B9 O# |+ }7 g' D. O/ _
public void spreadMoney(int money){# v  t- ~+ W1 B9 x0 h7 L, _8 O- k
    // Randomly place money in moneySpace
9 ]; I, c: S# c/ M/ N! m: A    for(int i = 0; i < money; i++){( d; z! T0 z: ~/ _+ W1 n
) z# _. L7 L% V* j3 u3 a5 K6 B
      // Choose coordinates8 {' e: C2 A$ r/ c* ^, e! ~
      int x = (int)(Math.random()*(moneySpace.getSizeX()));* A" J2 H2 H( `1 s+ |9 k
      int y = (int)(Math.random()*(moneySpace.getSizeY()));! s: k' a  _) u

0 I2 {4 |7 }6 W9 h. @. l      // Get the value of the object at those coordinates( W4 l7 ^& V! ?3 Z& D2 v9 }
      int I;- |9 p( Q( w. f, t: C4 S
      if(moneySpace.getObjectAt(x,y)!= null){
% Q8 q$ |1 Y  [! N  B        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
# H2 C* k  ^) M1 D" Z# ^      }
  T6 z8 n% o. l! B' g      else{% l. z+ E! q7 V3 ^% L4 c" I9 G
        I = 0;8 s( Y! q# l- Y  J
      }
# V/ O3 h% _. p4 _. l2 k7 U1 d      // Replace the Integer object with another one with the new value5 ^) l. K" h* p  k9 l
      moneySpace.putObjectAt(x,y,new Integer(I + 1));+ @# O6 {7 {4 z
    }
8 x' E0 s9 |; V0 \
这里面if(moneySpace.getObjectAt(x,y)!= null){
& Z2 ^* Q' _+ I! C+ c; C: A- ^        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();. P) V& R/ C' S+ U; @
      }
# e$ l9 J1 c6 M* E      else{. |7 W# I+ @0 U: x( S
        I = 0;
. x' o; Q- a; `: v- i7 P/ {" k  u  |8 K
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
* Y  ]/ v' v5 i初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-30 05:01 , Processed in 0.016196 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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