设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5327|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
( n4 b2 _: {7 Y& `. [9 }public void spreadMoney(int money){# N( f, J( i0 D. B
    // Randomly place money in moneySpace
# M2 v. l# J/ w% U2 r  d7 g0 y" _    for(int i = 0; i < money; i++){' {6 w3 V  v2 ~* V4 s

3 x6 |' C7 x3 i- Q7 ]$ d( g      // Choose coordinates
* U% j% k) Q& \5 P: ]      int x = (int)(Math.random()*(moneySpace.getSizeX()));
  v6 X6 D0 m* Z! b      int y = (int)(Math.random()*(moneySpace.getSizeY()));
" Z8 J' f$ d- n
: W. J1 d# Q  X* l' v0 U1 y3 @! i      // Get the value of the object at those coordinates
  l1 s( T# S0 A9 L, @* Q      int I;+ \9 z  _+ U* p$ c  W0 d  T
      if(moneySpace.getObjectAt(x,y)!= null){
* A  `: k$ U) h        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 M# S1 g4 {8 j6 E/ A' ~
      }
$ o9 S. [1 Q: G; s% C6 E% D. N) _      else{
# n7 A& F! h; |+ }9 k        I = 0;. N7 i8 o3 O* }" \0 I7 ~
      }1 c% i; \" }/ Q0 q) d+ q3 R7 j9 {, i# Q
      // Replace the Integer object with another one with the new value
! q3 F5 }# N7 _3 K* y      moneySpace.putObjectAt(x,y,new Integer(I + 1));' h$ q& w/ E3 e! m; O7 q* v
    }
2 P6 M( K9 Q8 r
这里面if(moneySpace.getObjectAt(x,y)!= null){+ z4 B# r( `2 |' V& w( P
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();$ V/ f8 ?0 P# N9 z, F# C
      }
, J3 [3 U9 ], v; z8 v      else{1 v& J0 t% W0 K% ]6 X9 _: j
        I = 0;
0 M: D% R# y6 L/ ]5 Y5 h
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
% J3 J# X* M# H5 \/ |- S9 N6 w: d初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-20 19:24 , Processed in 0.017072 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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