设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4291|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中+ _# ~& A" K2 k1 c" {+ F, a" {) W# s- n
public void spreadMoney(int money){
, f0 r* |0 M; R& {    // Randomly place money in moneySpace
5 e& T8 i5 G3 H: D) L    for(int i = 0; i < money; i++){4 E" T, A) P6 ?5 u+ Q" D

0 }. x+ y) z6 W% y# D1 v      // Choose coordinates1 B( r5 p2 }& E4 y1 g1 ~
      int x = (int)(Math.random()*(moneySpace.getSizeX()));4 f7 d5 o2 e$ i0 b
      int y = (int)(Math.random()*(moneySpace.getSizeY()));7 W- G9 Y0 d; \2 l) T( m' q

$ x$ V: c  ?+ e% n, M+ N( ^4 F      // Get the value of the object at those coordinates
. Z7 |8 a1 w9 T+ X- z& o# o3 `; z- j      int I;
- t! ~" B7 S  D; ]3 t0 N      if(moneySpace.getObjectAt(x,y)!= null){; N. h, X+ V: k3 n# Q
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
0 y# g; s; l) h9 Q      }5 B* {) s" ?% m2 l$ {5 a( p
      else{: |2 W% Y# n$ n  q+ G& `5 ?
        I = 0;
: n+ ?% f$ t# I9 ?- Z( }      }
" W8 y: Q- v% S% |. q! t2 s. C; {      // Replace the Integer object with another one with the new value
4 T) F; Y0 S& i" Q      moneySpace.putObjectAt(x,y,new Integer(I + 1));
$ A. K. j' P" Z- _" J    }
  w2 w1 Z0 o5 \. g" o& N2 y
这里面if(moneySpace.getObjectAt(x,y)!= null){
( x. X  k  |/ w& y: E$ \  [        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();7 U5 M" c( @" x" A" p$ w- m
      }5 v0 n# S5 r+ w' f- c  b
      else{
9 B8 S# d! V5 G$ d4 E        I = 0;

+ B3 y; F4 X1 C( G! Y( V5 S是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
! O/ v; v: b' ~5 ^$ I7 r2 h: M初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-3 10:30 , Processed in 0.018122 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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