设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4687|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中* ?0 n" N% K" @1 m9 W) h! R
public void spreadMoney(int money){. J( _6 B! C! B( ^
    // Randomly place money in moneySpace# R- z3 r  I, z2 ?# G& e: i7 w' L
    for(int i = 0; i < money; i++){+ A: Z( d. ?$ j4 t; c: Y

* V5 E/ r* K* C( U/ H5 C) P$ Z, [      // Choose coordinates
8 |% t9 w' @. r1 P      int x = (int)(Math.random()*(moneySpace.getSizeX()));' D  Q/ v4 ~  C0 ^) i0 z
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
% e  \8 V/ ]9 A. q; H' Q4 x8 B7 h8 C' n8 e3 Q
      // Get the value of the object at those coordinates
9 I& T/ E2 |  |: p5 t      int I;- {6 i' }0 p4 `& M# z: ~: t
      if(moneySpace.getObjectAt(x,y)!= null){
- Y6 W* i- F8 k        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
$ ?& @- d9 a; \; N9 s      }
0 h$ m6 x/ b) [0 s      else{
, K( p. s& p9 F2 E, ^) M        I = 0;& Q3 _, [9 S! |
      }
- g) `3 g7 @! ~2 k' [  e1 m" [      // Replace the Integer object with another one with the new value# P* e8 W' D. L4 x# [2 D, L, [
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
; |. V- h* q# e, J/ E/ ]- O    }
7 q# `- n6 f: v' M4 `2 R
这里面if(moneySpace.getObjectAt(x,y)!= null){
" r6 K* k3 e* |  T1 k) H8 G3 J        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();  n. L7 h( E( L6 m, B3 A5 w  u  @
      }& ~% j% p3 z% ~
      else{
: b# |& o8 M$ J: ~7 Q        I = 0;

) K, a6 s( ^4 b& w  q$ ^是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?; Y2 S% y5 ~$ f* z( w
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-16 23:32 , Processed in 0.013140 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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