设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5285|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中9 s0 O% q* D& J7 d( G( J4 m
public void spreadMoney(int money){
+ f1 U- D7 P& E5 g5 u; X    // Randomly place money in moneySpace
2 X) C9 ~3 a" u( J* K    for(int i = 0; i < money; i++){) ~4 q$ O; s/ z) @

1 l8 x) M" }" S) |/ F& V      // Choose coordinates
5 [' Z# h  P' t3 h9 Y* d      int x = (int)(Math.random()*(moneySpace.getSizeX()));
! e7 C) T' b) ?  `5 d! _! G" g/ v      int y = (int)(Math.random()*(moneySpace.getSizeY()));
5 n( j4 G$ \4 b2 j8 h
/ e7 g8 @' t& O( k1 s2 U      // Get the value of the object at those coordinates
  b+ P+ B" @; p      int I;
& _# N- D9 m9 R$ {1 i& ^- y      if(moneySpace.getObjectAt(x,y)!= null){$ X$ g& }: ?9 e: `9 T1 Z+ @
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
, i. K+ l5 b  G6 ?      }8 N6 \% ^6 J* G/ C9 H+ [
      else{  a  x( f! n0 D' c4 b& c; k* S. h, I
        I = 0;
: t  |: Y$ Q6 u0 R      }. n6 C! Q3 m/ S6 s& {1 e8 U
      // Replace the Integer object with another one with the new value& u1 ]- O1 d: J. @& [# Q+ L
      moneySpace.putObjectAt(x,y,new Integer(I + 1));! U4 X# J5 I+ X+ p8 h6 T7 i- |
    }

/ K5 X: A4 r% J& Q/ C2 L( c这里面if(moneySpace.getObjectAt(x,y)!= null){" S: p- {: t. L" l) v& R9 C. e
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();  K1 b! Y/ r" [0 t% x; V
      }* e3 b7 V+ F2 ~8 i
      else{
5 M1 [  |: Z, _" Q6 W        I = 0;

+ r' m% r: H/ \* @4 u6 o. m是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?: m2 G+ B8 [: z
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-6 14:15 , Processed in 0.013066 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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