设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5381|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
) K) n% \. H1 h; {. o  T8 b" ypublic void spreadMoney(int money){
) L) H* o( O0 W: O! d    // Randomly place money in moneySpace; J! ~! e$ x  T. l( ]
    for(int i = 0; i < money; i++){
5 T* I& S' k0 V7 M0 _/ C2 Y' S: r
      // Choose coordinates' L. y7 }! L% f: x5 B- C/ V
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
$ ~' |4 f/ |  X$ z) u+ g: r3 U      int y = (int)(Math.random()*(moneySpace.getSizeY()));3 {& v5 b% @( |% o
/ \+ ]9 a  B8 S' u- I& R) V
      // Get the value of the object at those coordinates2 U7 k$ W' E; M  h8 I5 w$ J
      int I;. W) J( u* V  e% q
      if(moneySpace.getObjectAt(x,y)!= null){
' k  t; K+ M6 _; s' g6 x% H3 Y: ^) F        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
3 Q8 v/ S* E, |7 l9 H' O      }& d# ?9 j4 _  z# W
      else{% f8 F3 B7 w5 i" y
        I = 0;
/ n9 H/ Q7 t0 ?, j# ]      }4 |4 _2 G+ M& D: L" b% A, m
      // Replace the Integer object with another one with the new value
4 _) a/ R9 h) F4 l# J2 b      moneySpace.putObjectAt(x,y,new Integer(I + 1));
: p6 i$ F$ \# ^2 g" O    }

. l0 R9 z8 _" d这里面if(moneySpace.getObjectAt(x,y)!= null){
( H% Y# t/ b: r* n0 }        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();, G7 n( x" O3 ^/ w' O: J
      }
! l' S7 q, A* }, s      else{$ p0 l9 V4 j! u. K2 i! }6 @
        I = 0;

' y  V' r0 u: C6 {是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
/ G( o' F! l" E" E- y% {初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-11 09:34 , Processed in 0.014926 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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