设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4122|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
1 h" v6 [; k# w3 y: }; hpublic void spreadMoney(int money){* k. n+ ^3 b/ T
    // Randomly place money in moneySpace
& q- l) k) T, I7 ?8 m7 H    for(int i = 0; i < money; i++){
5 a/ K! U% V% H) m$ H/ _
6 r' H2 q. l  Y/ I- ^      // Choose coordinates/ s/ f2 @* L$ _+ u
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
# x/ B4 G. N; c8 f0 I$ `% @      int y = (int)(Math.random()*(moneySpace.getSizeY()));9 u% `% ?4 @$ ?; Q% N" b0 V* a: V
1 M2 C' G4 ?5 i( \0 W7 {9 M! H
      // Get the value of the object at those coordinates; d1 F. O' p) }3 E, j  V
      int I;
; q' J$ h1 r( m! ]4 T8 a3 r/ ^      if(moneySpace.getObjectAt(x,y)!= null){
1 q# b# L' N4 p3 K" \        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();. ?* d% o( [5 `5 Q7 f. u. z
      }
7 r' O( D$ |: V/ N, u; u      else{: A4 W# E$ \% ]# Q) h
        I = 0;
; t; T7 w5 w& v      }% N$ U" M! N2 Z. A  K6 G; ^
      // Replace the Integer object with another one with the new value
; z" o4 f/ J( @0 z2 M: S! n( I) L8 h      moneySpace.putObjectAt(x,y,new Integer(I + 1));
0 u2 R& l- }4 A, |+ T: N& _1 ~4 S1 ^9 s    }
$ ^; s, \0 y) S
这里面if(moneySpace.getObjectAt(x,y)!= null){/ \7 ]3 K4 M9 |9 O, z6 Z
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();7 g0 v1 F; A2 ~1 j' u
      }& {, c" V  A9 q7 T0 r- t0 X& ]3 q
      else{% M$ Y2 w; ~9 ]- v4 O4 @* t1 W9 j- |1 {
        I = 0;
, w0 L% B0 q5 N2 Q) s  Y
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
* C" v% S; a; }- x6 T' I初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-18 19:11 , Processed in 0.014778 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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