设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4043|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
0 l4 C6 A4 c$ g3 L1 d$ _' Ipublic void spreadMoney(int money){
1 ]; f4 |- p- a    // Randomly place money in moneySpace; h$ h1 l4 o- u9 L, c( ]
    for(int i = 0; i < money; i++){6 D: c# z2 J. c; q/ w; K

* G% [0 M- a2 y: i. H* V8 [      // Choose coordinates
6 P1 Z& P7 o7 e/ Y% `3 a" V      int x = (int)(Math.random()*(moneySpace.getSizeX()));6 x; `  s) b, ]
      int y = (int)(Math.random()*(moneySpace.getSizeY()));9 S8 E" F; E& W2 @8 `) a" n

/ g1 d" c  d, {: m" Q      // Get the value of the object at those coordinates
/ A6 _0 M- U" v' x      int I;; _: |( a% J) s' e; m
      if(moneySpace.getObjectAt(x,y)!= null){0 {, T/ A% @/ x: ~" _9 i1 V
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();7 w- w4 p1 e: V8 [, b& R1 I
      }7 ~7 p# w8 M! F/ O0 @3 m/ A& v2 [
      else{
) E: N+ ?2 ~  J' o+ d        I = 0;
9 T2 `0 x3 p5 l2 v9 c      }
5 o+ q3 X" h5 x5 s% q! z1 w3 p      // Replace the Integer object with another one with the new value; B% G2 U& u& N2 ^. k+ N+ n
      moneySpace.putObjectAt(x,y,new Integer(I + 1));' f8 K* Q5 @) x: R3 D
    }

7 k* O  z) c- e( Z0 M这里面if(moneySpace.getObjectAt(x,y)!= null){" k  B( R, h) g6 H$ t
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();* T! h. f6 Q  ?1 E
      }
% E, N0 p2 X; F* u      else{
) e% a, W5 f* h) o' ?- U& C        I = 0;

) b8 F. V. X0 m) q6 E8 o3 L是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
; y) l# S/ s; w+ l- o& ]初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-5 17:46 , Processed in 0.013951 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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