设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4104|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中% N0 H+ Y4 Z* e2 A# w- d- i
public void spreadMoney(int money){* U' H2 [" S$ o2 g+ X% Z
    // Randomly place money in moneySpace
% j7 m+ h7 ~8 C& R* k    for(int i = 0; i < money; i++){
. ?# l* n( l6 S: Y4 \5 o4 C& B. M; o4 \3 T: u# J+ N
      // Choose coordinates
. Q; t4 L! l' t! a1 N      int x = (int)(Math.random()*(moneySpace.getSizeX()));$ z* M) w( H8 O% O2 C3 K3 x
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
9 }# H" w9 w" O( C+ m: ~/ r  @$ m( X7 T
      // Get the value of the object at those coordinates) Q+ }& [: }, N. p. H1 \
      int I;9 E/ Q! L$ C7 ^, r
      if(moneySpace.getObjectAt(x,y)!= null){
7 {. F6 d5 b" v9 @+ \, j" b8 r        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
6 |4 Q# w# T+ u2 d! X      }! r- i# Z# ]' s
      else{" G; z" O! C" s3 M
        I = 0;
0 `. @. Y. r; B0 M: F' `      }5 q1 H1 o: p! h& C# v% G( b0 P% c
      // Replace the Integer object with another one with the new value2 h4 d5 H' h4 T
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
; F" q$ G: K) `) x& j% p, E/ |    }
3 d& ]8 S/ ~% C) D8 e
这里面if(moneySpace.getObjectAt(x,y)!= null){
: X! |, K6 `& W. Y( G        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();8 n% c  H- Q+ d/ w
      }2 l0 L# Y) T8 I: l
      else{
1 S: [) f1 H: ^! x- m9 H* Z        I = 0;

$ q% r! L' q. d: O: K是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
3 ^- F4 f, }! @6 G& ]5 _. h初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-15 00:19 , Processed in 0.014088 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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