设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4221|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中, s/ j+ Q, v- v, }2 Z
public void spreadMoney(int money){
5 _+ k# N- ]$ T4 h$ U: n    // Randomly place money in moneySpace
2 @: j9 h9 F. H* ?# t. B    for(int i = 0; i < money; i++){
) K0 o0 M7 }- |" d
. i* w* S; I1 N0 d  |      // Choose coordinates
, c$ C" U8 w6 j, C+ c! D      int x = (int)(Math.random()*(moneySpace.getSizeX()));& f2 Y3 N) \+ D7 j7 E' y
      int y = (int)(Math.random()*(moneySpace.getSizeY()));, Y. W6 n4 z' ]2 e7 i
) q- s$ [! |* S4 `4 e$ e& S. e" x( c1 b
      // Get the value of the object at those coordinates
/ X; h8 c- g/ _  l      int I;
' X; X* Z( M# B  K( G6 s& ?      if(moneySpace.getObjectAt(x,y)!= null){
0 _' K% l  B& c- g( \        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
$ p. @( @! l2 y7 p      }
" i7 A# Z& N3 B2 z0 Q3 j      else{# U3 V" B" \: ]2 ?# g
        I = 0;3 W) J, q( u5 C. j( X3 u* S6 y
      }
. W( r4 z, ?! r1 H3 T7 J- O      // Replace the Integer object with another one with the new value4 B; a! q" q6 \  \
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
9 z* d: H0 c: K    }

  O, k! \2 S. S6 ]9 _7 Z+ b$ u这里面if(moneySpace.getObjectAt(x,y)!= null){
6 P; K8 A/ s) }# k9 V        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
6 P, R3 ?7 R" ^5 s      }3 @* B' B3 ]# M' y& [: @
      else{" f3 T6 ]# v, o' ?+ y5 v0 U
        I = 0;

' `6 a" p& ^6 L# D是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
) k! W/ n8 X% @7 W4 \( E1 q4 R) a初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-17 11:04 , Processed in 0.015044 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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