设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2759|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
5 v' }9 [& N3 b+ v$ p1 dpublic void spreadMoney(int money){
  d. ^$ Y8 J. t7 x    // Randomly place money in moneySpace' ~' n; J0 W9 t" i. T$ E! H
    for(int i = 0; i < money; i++){
, c, u0 q8 F$ E, ~/ p8 r
) k4 K/ `5 V' }) X3 @# }2 j      // Choose coordinates
6 A& _* y9 y4 c. n( R; g1 w      int x = (int)(Math.random()*(moneySpace.getSizeX()));
7 g9 y* V1 H. }      int y = (int)(Math.random()*(moneySpace.getSizeY()));
( ]" b' f( C" c3 S. m4 ?) M4 m
6 B. ^: }. B9 w4 @  o5 b      // Get the value of the object at those coordinates
9 S! P" `! J" d, e      int I;
( f4 C. Z5 Z: Q! l9 f; I      if(moneySpace.getObjectAt(x,y)!= null){$ _& L4 f. j' C! ?
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
6 J. U' t7 e! _3 |9 \* z% g      }
3 E$ P" g2 j- j' X- v" @3 W      else{/ j9 M& c+ @) p$ {' p
        I = 0;1 G( ]% [3 b. h% g% }
      }
+ M+ V: F3 O, B: c  |      // Replace the Integer object with another one with the new value
  D# T5 t5 V$ |  W. w      moneySpace.putObjectAt(x,y,new Integer(I + 1));
/ W8 u' l7 {* l    }
' c' }" c0 ]) l0 d
这里面if(moneySpace.getObjectAt(x,y)!= null){
4 u# b6 [6 C' ]# }' t        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
* {7 i1 E9 w# Q      }4 H. Z. F# B; A$ i$ m# [
      else{
" i% K4 a1 H4 f  t3 [        I = 0;

- F1 J5 F( v$ w3 I3 S' T3 \是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
; A9 Q6 }9 y% j2 p0 j0 d初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-20 08:16 , Processed in 0.012059 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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