设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2781|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
4 T9 L" @. _* ^) j; X- Ppublic void spreadMoney(int money){
' v+ z' N" Z& N  f+ h1 |; @: N    // Randomly place money in moneySpace5 r4 C2 C1 d0 P
    for(int i = 0; i < money; i++){+ T6 M6 i+ q' y+ P8 B" K" {, |3 m

+ W6 Y6 ^$ F% i+ b' c5 W3 g1 c- {      // Choose coordinates$ G9 m6 |( n* ~6 ?! b7 Q
      int x = (int)(Math.random()*(moneySpace.getSizeX()));/ ^" [0 k9 e6 K
      int y = (int)(Math.random()*(moneySpace.getSizeY()));; ^. W% d7 R! x& p. {

  F' @' ~. K& c      // Get the value of the object at those coordinates
3 X3 K. M7 A8 d! ?. v7 q3 {# U" s- q      int I;
* ?% R6 @7 x" f0 J* V      if(moneySpace.getObjectAt(x,y)!= null){
1 ~, M* H7 B) U9 O$ t, u( \9 u- @        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();9 g7 J( X+ x9 O
      }
! M. C5 v7 T1 T  a" S* u      else{+ o# G2 ~1 y. ~0 b3 S
        I = 0;! I  k2 O  J1 c7 f" Y; a4 H- M
      }: N( X' v. |' C( {
      // Replace the Integer object with another one with the new value& k" t# M; ]$ z$ {6 }9 J
      moneySpace.putObjectAt(x,y,new Integer(I + 1));! B! ?4 u# P. G( ^+ `6 q
    }
# o6 W5 G3 Z5 r% |& K
这里面if(moneySpace.getObjectAt(x,y)!= null){+ k, }/ J% f: P$ S% h7 N( w
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
, b! F. }' @3 |. m! V+ O      }" ]! j, g' e, E+ b& Z
      else{% f" _) e! f/ i& p, E
        I = 0;

) i8 `( B, {% G* p- h  M* a是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?9 q; S; x2 @' u. k; w
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-6-17 23:52 , Processed in 0.013008 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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