设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4632|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中$ Z( o" f% y% B1 D9 K
public void spreadMoney(int money){, @: ~. y2 o" H- q" @
    // Randomly place money in moneySpace
9 o% z4 n/ A2 K# ]' @. f    for(int i = 0; i < money; i++){, C- p9 @1 B! I% `- [3 S4 f  z- H' G
2 h! F3 i. }# \6 `
      // Choose coordinates$ \2 U7 d) K1 y# ]# d/ o
      int x = (int)(Math.random()*(moneySpace.getSizeX()));& \/ j- `: @% d1 I7 ]2 m) q+ l& ^5 X
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
7 U9 J# m8 v  c- f
' E8 v: P# ^, y4 E4 S8 `) t6 \% i% A      // Get the value of the object at those coordinates
: V# N" Q! R2 l  c8 Y0 e8 R. A      int I;' Z. O# I8 [' Z4 K* z
      if(moneySpace.getObjectAt(x,y)!= null){
+ X4 a) c( l# A6 r        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();7 A; s, H6 \6 T+ O7 d
      }! ?+ c, S  R  O- W* f
      else{0 F- s8 b7 e( z/ N% U3 w) e+ d2 v5 p
        I = 0;8 {" l5 {/ h/ l: I
      }
. {* P. u# S1 b& Z3 `      // Replace the Integer object with another one with the new value) Q; `  H, M& n
      moneySpace.putObjectAt(x,y,new Integer(I + 1));+ X5 M, S4 x% K  g
    }

  `5 W' N8 y) A0 r这里面if(moneySpace.getObjectAt(x,y)!= null){
( r( b/ s% L7 |. p3 `7 o) H        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
0 v. x! N7 ]' H& @      }
: J) ^: G# T% V6 D      else{
' a& P9 i1 n& A, }$ f: L        I = 0;
! r5 ], N/ v6 ?3 ]# h0 K
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?9 c  b: J2 U7 i, P7 x
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-3 09:21 , Processed in 0.020950 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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