设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5428|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
! [( X* h: `4 O  a- S6 y. Apublic void spreadMoney(int money){
$ i: x. m/ G) F. B, C    // Randomly place money in moneySpace6 J( P5 P* `0 n  H0 N5 C
    for(int i = 0; i < money; i++){* j8 {" D7 v8 ?# o6 b- s; f

! r3 y- _8 i& }! Z+ A0 K# }9 t      // Choose coordinates0 ~3 w- C) [- _9 w. |. @" m
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
* E: s9 ^' _& l% z      int y = (int)(Math.random()*(moneySpace.getSizeY()));. r; ]+ C9 \# P$ [" h$ j
4 K( i& A; k. L$ Z& N
      // Get the value of the object at those coordinates
& t/ m6 C% \; S! {, g) m6 Y3 I  f      int I;9 H7 A6 q" [0 J, [! [5 K3 m9 l6 a
      if(moneySpace.getObjectAt(x,y)!= null){+ B4 O. W9 e# X* i+ M$ G9 _
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 c+ y, S' k( L: R+ V2 q
      }
. N0 v7 h7 I: P4 ]  T. U& Z7 A      else{& M/ q3 z6 Q4 b
        I = 0;3 F! F. ?) u/ G' p5 ^6 L- E
      }' o6 W6 u- w  k4 Y0 W0 M% x, T
      // Replace the Integer object with another one with the new value
! B1 m1 R, ^: U  \" N& Y2 r, X% }      moneySpace.putObjectAt(x,y,new Integer(I + 1));: ]7 }% S( X+ v' E  J* @% n
    }

) y2 Z  t" L4 N- Z6 |. X- Z这里面if(moneySpace.getObjectAt(x,y)!= null){
: c6 s, r/ L4 `/ o        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
2 Q! [1 _4 E3 r      }
0 q6 a1 U- h1 P# t) q! m      else{, b& _/ F* C- M/ A
        I = 0;
; X1 \  g( P  E# Q, L
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
5 q  P' s. z7 R/ \( N% t3 P9 ]初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-18 03:50 , Processed in 0.015383 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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