设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3909|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
. a4 q$ j4 l$ ]) |, Z4 `  L' dpublic void spreadMoney(int money){
8 o$ Z, `+ ^. k8 H' X) Q    // Randomly place money in moneySpace& J6 Q0 x7 T$ N+ w4 ^9 v; t8 y
    for(int i = 0; i < money; i++){
) B8 v+ r2 z7 Z8 E
2 N+ Q% e' E8 Q' E* H      // Choose coordinates" a. L# O& E8 x
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
  }# W3 z* w, C8 u8 |5 c, `# M      int y = (int)(Math.random()*(moneySpace.getSizeY()));2 L# K- f* P3 q# N
0 a6 v- d2 q1 a4 {' {& B0 L5 Y
      // Get the value of the object at those coordinates9 u8 d3 k0 m& k9 i9 Z
      int I;$ _* U9 j4 ~5 ~  D' ]& I
      if(moneySpace.getObjectAt(x,y)!= null){
. g& [& {( ?7 K, P4 J1 o+ G- @        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
/ G" W6 O" w& f# a$ Y      }" c4 K6 n9 @. f/ `! X+ o) j4 }
      else{
5 V1 a2 X- Q. t: D7 D        I = 0;8 z: T& \  z3 J2 K& P0 U2 F
      }" l7 p2 b* o( K$ ~8 n
      // Replace the Integer object with another one with the new value
$ l- m" {0 M; E+ f3 R      moneySpace.putObjectAt(x,y,new Integer(I + 1));8 l% E7 X0 K+ K. F4 h  [& G
    }

2 ^* d% K) M& `% w0 J这里面if(moneySpace.getObjectAt(x,y)!= null){! G- x  v0 k1 }: z
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();6 v% S4 s0 Y0 n$ ~
      }
, t' K/ i, [2 Q0 w. `      else{6 m# y& l$ B/ c8 e+ x
        I = 0;

; D' X# S" G8 {  F) O; T. s是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
  b$ U* h4 z  y; j/ \9 a) Q初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-19 07:43 , Processed in 0.013128 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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