设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4400|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
" v! _. ]$ C. o( m1 spublic void spreadMoney(int money){; B+ t5 j8 v' s/ @$ o" C
    // Randomly place money in moneySpace3 y- P9 w. x- z  ?8 ?
    for(int i = 0; i < money; i++){0 \% i% i; w! K& z
  _* Y7 ?  E, o0 T) \
      // Choose coordinates* O9 N1 t* S' \3 ^
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
+ S0 W" e& Y7 o0 y# C+ Z  v      int y = (int)(Math.random()*(moneySpace.getSizeY()));
3 s, h" Z3 P, F9 I' T' H( I% S) v3 J4 |# g) k
      // Get the value of the object at those coordinates' j$ z: K, `$ r: {3 Z  G
      int I;2 N3 S& `' u, _) I& U
      if(moneySpace.getObjectAt(x,y)!= null){
8 a  }1 q: K1 G        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
" s: E) o1 b8 F8 n! T. Q) a, v      }
3 @2 I5 M6 X! |. M1 x# {1 `      else{4 ~: y: Y1 M" F* _
        I = 0;
# c( u. T/ T7 z      }
6 w; l' j( H$ e6 `      // Replace the Integer object with another one with the new value
* z+ s5 c2 }* s: X; h* v% f: {# E      moneySpace.putObjectAt(x,y,new Integer(I + 1));
$ M% t  U3 g) {' E, Y" G) F    }
/ w$ b8 G% f$ Y7 g2 v6 r9 Z( r
这里面if(moneySpace.getObjectAt(x,y)!= null){4 v6 A' \. I! P% W" A9 Z/ E) K
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();5 N9 g& R0 T" x
      }
/ {) [) [, n! S, ~% l3 r0 }      else{( H0 @" l* V/ T4 K5 D8 `" ^6 Z
        I = 0;

& [/ G; \- Q; l是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
( ~3 h% G* W1 T- Q) \3 j7 A初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-18 22:41 , Processed in 0.016243 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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