设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5081|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
; z3 R# Y! }' r8 f4 G& w  O- V& r8 ppublic void spreadMoney(int money){
: w6 u  s, }9 k4 ~    // Randomly place money in moneySpace
$ @. W; T& I, N4 K2 v( a    for(int i = 0; i < money; i++){
! W' w# x; B6 N  o- H6 X$ S' g# I+ F% v" D+ ^: z
      // Choose coordinates, y# f* Q  v0 E/ q) ?. Y
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
' J/ O+ E; H. o) Y' N2 ?      int y = (int)(Math.random()*(moneySpace.getSizeY()));
4 @1 d( d2 h3 }9 O8 x: k+ h' L& D) A0 G; C. ]2 g+ `0 ^4 n* y5 t
      // Get the value of the object at those coordinates
: @; Y3 k5 ^8 L# M" X- g* ~: {      int I;  @2 F& q, X" s& B1 z* _3 e
      if(moneySpace.getObjectAt(x,y)!= null){1 N+ b1 M% Q  P, a5 ~# L
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();0 H1 k. O9 i- M5 R  r( b  B
      }
. R& t- _+ @5 Q/ r' S- K) d      else{
5 V6 l" ]+ ?+ c0 H9 p/ p        I = 0;  U0 l- N( r* X2 ~: N8 Y
      }
' I1 v4 X! t, u! k  a  O& i# U      // Replace the Integer object with another one with the new value
; I, e$ v) J# D" g* f      moneySpace.putObjectAt(x,y,new Integer(I + 1));5 V/ d: }8 W4 K- D4 a- I/ e3 ~6 j
    }

. y4 G4 m+ N! c1 \& P这里面if(moneySpace.getObjectAt(x,y)!= null){
8 o( q) _. [( {2 M# a# e, S% Q        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();+ p- D  v7 K0 L7 P
      }
7 k! e( }# C" E( d4 F      else{
6 h) x$ ]" d* E. J2 q        I = 0;
( J0 Q+ m1 x6 y* S& \( p7 ~
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
$ q( t6 i- z5 H: m% q7 x3 y初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-19 11:41 , Processed in 0.014334 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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