设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3989|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
+ h0 E. B3 i, w9 ipublic void spreadMoney(int money){
* U5 t* Q. g& ~# d# C) w; Z    // Randomly place money in moneySpace- }6 W5 `# E4 \
    for(int i = 0; i < money; i++){1 _9 A$ }+ l9 K6 Z) t

5 ?  A6 m9 T# K# O: v1 ~      // Choose coordinates1 ?+ Z* w0 X  e4 G; ^! y6 P% w
      int x = (int)(Math.random()*(moneySpace.getSizeX()));$ S, |& ~9 Y2 w/ c9 R
      int y = (int)(Math.random()*(moneySpace.getSizeY()));/ ]1 _, [! _, L( W6 Z; H1 `( e

; U5 M# e: j4 n: @      // Get the value of the object at those coordinates& L+ B1 |) ]) c6 H
      int I;+ C; n3 h$ c- W! O! [
      if(moneySpace.getObjectAt(x,y)!= null){0 y0 v4 [6 }% w# q
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();: ?- b; _" J1 f8 ~0 D' |0 b
      }
! G# Z+ B8 ]) q' B9 q      else{2 F$ _6 a: _. ]- L" L. p: _; x
        I = 0;
' N7 k8 B! }% |1 u$ T      }
& j/ ^( n5 I2 D: Z* [/ x" i      // Replace the Integer object with another one with the new value4 ]# I4 @% G4 p8 e/ q
      moneySpace.putObjectAt(x,y,new Integer(I + 1));8 I$ n4 q) p! r8 _: N, ~' z! P9 _
    }
# ~3 p3 d* i) t! C! [. U! W2 X: i
这里面if(moneySpace.getObjectAt(x,y)!= null){
/ h- F  n. y1 x& n2 n        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();) y3 y- h& }: @' V  |/ F
      }3 [1 _) F! G; _1 i4 m
      else{5 A  g2 v3 }- S* H
        I = 0;

6 h. s; o* }& ~4 L是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
7 s7 U1 Q1 b, \/ {6 ]8 F. i初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-8-17 17:13 , Processed in 0.012942 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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