设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4113|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
- P0 }/ |! N9 W3 u# Wpublic void spreadMoney(int money){
0 L0 Z" S: N& J! H    // Randomly place money in moneySpace; Y- q) [# M0 i( _' g" p
    for(int i = 0; i < money; i++){
  b  s/ P& f! t4 A/ z
9 D; W! E+ J# y: r3 c      // Choose coordinates
1 Y% n( p. B& f' }( a& o      int x = (int)(Math.random()*(moneySpace.getSizeX()));
5 f3 c$ p, m. P; N; L9 q      int y = (int)(Math.random()*(moneySpace.getSizeY()));
' k: e' i/ n) d6 Y& V1 a- i' d: g
0 `  N7 \% C8 D; g+ t2 }      // Get the value of the object at those coordinates1 e8 g+ W0 z  i. y
      int I;0 F% E7 B6 q# e- }% _$ o
      if(moneySpace.getObjectAt(x,y)!= null){, l* t9 V% L& Q. N. p
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();$ K3 l. X) r$ _2 l4 Y8 S7 i
      }
9 M# t$ v" X: L) r4 x      else{
1 s- N% {1 v/ R7 B# @        I = 0;
: W# E  [: w, Z, s5 p  i$ l% ]      }
7 n9 y5 e) K0 ~* g, {# H) Y" v5 I6 m      // Replace the Integer object with another one with the new value
5 J, O1 {, `1 m% \- c; B( e1 f      moneySpace.putObjectAt(x,y,new Integer(I + 1));
2 c* k4 {7 F. w' ]& s9 Y. ?    }
- |- W4 |5 _+ _) J: ?# ^7 C
这里面if(moneySpace.getObjectAt(x,y)!= null){  i1 O; O$ Y4 x% z$ L0 [
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();+ u+ x. [. ?5 z7 h
      }
8 s6 x- k8 L) E! h- C      else{
5 K( V. Q  @3 X4 L3 O        I = 0;
! c& T$ o) Q: j
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
5 a' s/ I9 j+ _# G初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-17 05:02 , Processed in 0.015296 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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