设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5212|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中  @3 Y9 Q, R1 [# G% Q8 m/ e$ l1 P) F" P
public void spreadMoney(int money){
. \( u1 r4 m% i9 _8 Q- ]$ B" Z    // Randomly place money in moneySpace0 A% L, s/ N1 C2 s+ ~! L0 r6 s
    for(int i = 0; i < money; i++){
# x* }" F  m; U; s/ R. S- V3 u* _# U# a/ X
      // Choose coordinates1 p0 x- E- p/ O7 }- U" d; v
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
5 A- J0 |  l- t5 ^6 A      int y = (int)(Math.random()*(moneySpace.getSizeY()));
+ l( F" B/ g/ d" |/ b- e: I* d- F$ l4 g
      // Get the value of the object at those coordinates
0 o% R' C- X4 `9 x1 V      int I;
2 }; R" C& j  h      if(moneySpace.getObjectAt(x,y)!= null){& f2 j6 H1 T* z% H0 |1 p" m# Q9 ]- k9 b
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();  z1 ^" C$ J, I( d
      }; x$ B7 z0 Q( B4 R9 h7 }5 r8 D8 J
      else{/ {) K5 X2 z) X* T6 O
        I = 0;
0 v2 W- w  q% s4 j2 _7 l' ~      }8 O. m( @' D6 Q+ e0 `* |
      // Replace the Integer object with another one with the new value
4 H+ }# v. g, r+ s' G5 B9 R      moneySpace.putObjectAt(x,y,new Integer(I + 1));# P, g* {( \8 F; {' a
    }
; Y9 J8 }  p! @9 }6 \: \6 _
这里面if(moneySpace.getObjectAt(x,y)!= null){
8 E0 E: \$ N* D! c. c# p        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();5 v6 G- K9 v/ p$ G: L3 B) x
      }; _9 i  O+ G4 l9 i  I
      else{. k4 S6 S2 H) T! K, O7 l# @
        I = 0;

7 F- t! e4 Y, x6 I; i是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?6 B& D" i, L' G$ j3 y. M. Y
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-24 05:56 , Processed in 0.016105 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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