设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3722|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中: T0 r" {' t7 t5 a) c/ i& [. r
public void spreadMoney(int money){3 J2 U" R! s0 ?* N4 @# f
    // Randomly place money in moneySpace
$ U- b" W% [7 T9 d    for(int i = 0; i < money; i++){
; y2 I* o# N9 G. B3 H8 F' v; d* W) j' J3 O( }" m8 t# b5 ^$ r+ p
      // Choose coordinates
+ M9 U; g* |$ ]$ z      int x = (int)(Math.random()*(moneySpace.getSizeX()));
1 f) L6 e6 W6 j; s" M      int y = (int)(Math.random()*(moneySpace.getSizeY()));2 M: ~+ b# e" h
" h) u8 n6 c. m% r/ h
      // Get the value of the object at those coordinates( v  {3 X' ]* N8 s  r' _+ W; P. e
      int I;
3 j8 r. x1 S! [      if(moneySpace.getObjectAt(x,y)!= null){  T) p1 _# l$ u6 j
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
9 f& s% g8 ^: ~      }
2 `8 A) P% e5 ?; C8 f. k6 K& I% d      else{
$ E" S9 @( ?1 \8 u2 x" q& b( @. l        I = 0;  \) l$ j' W0 K" L5 R7 H2 n) L' V6 F
      }
2 M2 j5 j/ ]+ o, E$ n9 U0 F      // Replace the Integer object with another one with the new value
& o0 b/ ?# _7 l      moneySpace.putObjectAt(x,y,new Integer(I + 1));8 ^: e# R. R  n. c0 s
    }
& H+ d$ J! P# L, K2 Q, X7 o! j
这里面if(moneySpace.getObjectAt(x,y)!= null){' p# M3 B* w. V' W* }: Z& L, {. ]
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();6 K# T- I3 c! z' y; `
      }7 ]8 r2 A2 K; Y. [
      else{
. _. y7 ?" T. ~7 v1 O        I = 0;

7 H3 C- k' o6 C' j. Z是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?+ Y3 g; r5 l! t; e5 L' q( @6 r7 y
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-19 16:37 , Processed in 0.015812 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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