设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5328|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中) |; s8 b6 O1 o, E7 d5 ^% |
public void spreadMoney(int money){
  T3 c, Y( O8 ~    // Randomly place money in moneySpace
0 @8 O4 ~2 ]5 }5 Q5 `$ u! \    for(int i = 0; i < money; i++){) V0 O# E" f$ Y$ i2 O
& r% c$ s3 z7 x: o6 f' C# M% Q
      // Choose coordinates
: L+ _2 k& N* Y9 N  Z      int x = (int)(Math.random()*(moneySpace.getSizeX()));% d) _7 j6 l+ |( m- I
      int y = (int)(Math.random()*(moneySpace.getSizeY()));6 K9 l4 O: N0 N# ]
( d0 ~. d9 l& B  A/ c% H
      // Get the value of the object at those coordinates) ~+ J; a: F3 m
      int I;
& y2 j; w- k% x8 x      if(moneySpace.getObjectAt(x,y)!= null){( a! M  O3 `- Q: Q
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();# r: H# v! b, ]
      }! a, }5 V  ?1 T: a) A
      else{
' @( e- s# w, K7 e6 z# Z0 w* b0 R1 R        I = 0;7 e" {; X4 H& H# f
      }
0 ^# p% x6 S* i      // Replace the Integer object with another one with the new value
  ]. ^9 }4 P  [6 e+ o      moneySpace.putObjectAt(x,y,new Integer(I + 1));: x; x+ B* A8 y  l
    }

  H- O6 c, c! H4 x5 G3 ?5 ]这里面if(moneySpace.getObjectAt(x,y)!= null){
  G. |) p+ r# ?, C. m1 P. A  S( \' N        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
0 t. [4 I7 h& g      }" h4 h6 C# N/ e4 d
      else{* ]" y7 L$ @! Q9 V
        I = 0;

% f$ o( i( n  Z# u是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
2 M; [, `4 [. d7 \$ H# V7 |初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-21 06:44 , Processed in 0.020585 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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