设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4416|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中2 f+ Y2 a) z# g, d* h; g- B
public void spreadMoney(int money){" [0 I; o6 K7 Y4 X! }
    // Randomly place money in moneySpace, [6 a, i0 ]$ ~, X% ^7 [
    for(int i = 0; i < money; i++){
" @* D; L: M9 M; @; n5 `) ^* Y9 Z# J: Z0 X) j# c
      // Choose coordinates
* j: t* O3 a8 j; l7 Q      int x = (int)(Math.random()*(moneySpace.getSizeX()));
3 t4 p! R9 e. J: b% v; r      int y = (int)(Math.random()*(moneySpace.getSizeY()));# L" Y6 B8 M& C  g
) c3 a3 c9 p& W5 s$ u' m/ d2 |/ Z0 V
      // Get the value of the object at those coordinates$ h# d9 i: M  X; P% }5 O
      int I;
6 v) G# [7 A+ x0 C6 i      if(moneySpace.getObjectAt(x,y)!= null){
! L( d- p' W3 k& Q" }        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
, t/ ?* G2 H: R) j# Q3 g* Z' x      }& z( G7 {4 h3 x9 O5 t
      else{
  Q  h  H! ~5 _        I = 0;: Y/ U# k! P  I" Y+ ]4 A
      }
7 W3 D( b( y) ?3 {" G9 I      // Replace the Integer object with another one with the new value
) Z1 w5 o3 K. Y6 |% L$ u; q      moneySpace.putObjectAt(x,y,new Integer(I + 1));
8 `- h$ A: @8 A* A" v    }
7 q! Y0 z% N8 _
这里面if(moneySpace.getObjectAt(x,y)!= null){
! L4 U( f8 l7 Z* u3 f! t( ?4 B        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
2 {* O* t+ C4 \6 r' M* C      }
- K& O1 R/ I; B( ?+ E      else{6 [1 I, A+ A4 r4 O$ u
        I = 0;
( }' S  u& Q& J! ]* q9 r
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?  {/ ^: f% b5 f
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-25 19:06 , Processed in 0.016295 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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