设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4711|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
% P6 o* [$ V" T- h, Npublic void spreadMoney(int money){
( m/ T% E2 }0 J0 k, e: {    // Randomly place money in moneySpace
% C7 K6 s$ e  M; a  S% ?6 J0 Y1 p    for(int i = 0; i < money; i++){
1 Q1 p/ H: |6 w: Y; |6 F& \/ h- f* c' h, k+ ?
      // Choose coordinates7 H# G( p& H$ i# t$ w6 i5 \! q
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
$ y4 b/ n% z* E$ A' T      int y = (int)(Math.random()*(moneySpace.getSizeY()));3 ]& j# ~  [2 x5 B) r9 `  s$ q/ Y

7 W! k' b- o) S: _2 h8 @6 ?      // Get the value of the object at those coordinates
$ q7 K; u) ?( P% g7 O      int I;! w! Z9 F, }2 R2 e5 F3 U) G! A- _
      if(moneySpace.getObjectAt(x,y)!= null){' b, ~, d8 ^6 \2 l2 x
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
- z1 T( e/ H  p2 s      }
" h% f+ i# n$ p- U1 N      else{& b7 f6 b& t1 a1 y
        I = 0;9 x* o7 s" K) s3 ~
      }
& {8 m/ r9 f/ R6 E2 b  H      // Replace the Integer object with another one with the new value
& r. s: z3 C# L: l1 o      moneySpace.putObjectAt(x,y,new Integer(I + 1));
5 _+ A9 ]% {" X! |    }
; Y1 @0 Q4 t6 F7 Q' w
这里面if(moneySpace.getObjectAt(x,y)!= null){
9 J2 G% ]1 H4 H8 q/ i/ u2 t        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();) {# G% Y3 \1 t0 N/ d6 `# E/ ^* v  |
      }
4 q9 T  M( U5 E      else{
0 K2 I7 P/ @& ^3 @. {+ C        I = 0;

5 r! R* d/ U+ {  y  m3 {' |是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?* }6 o9 ^3 R3 |
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-24 15:14 , Processed in 0.017708 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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