设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4680|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
$ R2 N* j6 B- n4 vpublic void spreadMoney(int money){- u6 Z0 h; v7 h' B1 m! i
    // Randomly place money in moneySpace
7 t/ e  k" K3 `, m    for(int i = 0; i < money; i++){' e+ |# D8 a  ]2 L

" m0 C  O0 }, n- Q; q1 I. y4 `      // Choose coordinates. f) k. e2 O. b3 D  c
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
+ ]2 k, `2 s2 P      int y = (int)(Math.random()*(moneySpace.getSizeY()));) k0 g! y. C) F

6 C: p& I- a' B& G. r( Q      // Get the value of the object at those coordinates* G1 u; c3 Z2 J4 k- k
      int I;/ `) k  l0 z+ F8 T' R9 c; F
      if(moneySpace.getObjectAt(x,y)!= null){
. ^. d* ^% M, H        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
0 Z: B& p/ j( a+ F) x- Y      }4 S9 D$ v8 a, K# O, l' Q$ N
      else{
2 v: r. G+ O# N$ O# Z+ }$ i        I = 0;
& ?  ]: E$ `' t) U& z0 N      }" z+ K- m) G3 i4 l& ?
      // Replace the Integer object with another one with the new value* M9 S) u3 `" Y+ D2 X
      moneySpace.putObjectAt(x,y,new Integer(I + 1));" Q4 e2 r+ x0 L( T6 v9 E
    }

3 Z( x# l% t8 h; n这里面if(moneySpace.getObjectAt(x,y)!= null){
. y6 W0 p) H  B        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();) r- j# q( O. X! s  E
      }% y) l# U" S. O) s* }/ s
      else{& U; k7 w' Z- t. K4 x6 Q( H
        I = 0;
0 B3 x8 ?+ L1 S
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?! d0 w3 Y: q/ q* \. m
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-15 20:12 , Processed in 0.020840 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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