设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4997|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
2 B  Q; Y! g( ^7 Dpublic void spreadMoney(int money){/ v" q# y- d+ p) ?' ?
    // Randomly place money in moneySpace# c( V" `1 K9 I$ q3 [% q+ m
    for(int i = 0; i < money; i++){7 S" x( f( O9 T( k9 R) R1 ]9 H. @' i
" M. E- L" b+ l; w: y
      // Choose coordinates
- W' ~3 L) Q* E0 V      int x = (int)(Math.random()*(moneySpace.getSizeX()));7 I+ j% R: s# E: J' |
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
/ h7 f0 G' H8 v1 y
. B5 R# I$ H) n: u* w% F7 v      // Get the value of the object at those coordinates
' k/ `' D& N; B. h( F' K( k      int I;
/ x/ `4 B+ r) @& D6 j5 j: M      if(moneySpace.getObjectAt(x,y)!= null){; D& ?0 ?+ }  q- W
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();7 t: V% }; P, X% k4 I2 u
      }5 z& y3 m: }% I& L- n( B8 i
      else{
9 p* l; K9 ~$ @  q. L& N        I = 0;: k# @) |) W, a8 E
      }+ v( X3 b) e3 K- M: {" u0 O3 `
      // Replace the Integer object with another one with the new value' C# l( q" ~% j" o
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
- O. ?9 z4 @, n    }

1 ~6 n/ E" i! `8 {- P) M这里面if(moneySpace.getObjectAt(x,y)!= null){
) [2 @2 @/ Y' a+ G' q9 _        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();# ~7 r$ J0 U" Z- g7 w' x# E
      }
; y1 K  c5 K2 `/ V      else{
' {6 `8 |+ |. b' c' u        I = 0;
! n5 Q( \" U- l( v7 u( D0 a6 Y
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?1 v3 I/ ]& O4 b0 i! S) ~
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-14 16:18 , Processed in 3.273209 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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