设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5005|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
- S! @& ^3 i2 k, C3 T6 Vpublic void spreadMoney(int money){
, g% |) z. v/ o$ R. |2 G    // Randomly place money in moneySpace
0 \7 C3 G* c- @) V% e2 N    for(int i = 0; i < money; i++){
3 T! u/ X- E6 M# U( M9 D% c5 L3 _; ~/ S. R" x' R/ f
      // Choose coordinates3 v6 u0 b% I7 x; ~
      int x = (int)(Math.random()*(moneySpace.getSizeX()));5 [0 z8 R0 }6 {. ]
      int y = (int)(Math.random()*(moneySpace.getSizeY()));7 t0 }0 C5 m+ \* ?

; z. L8 m# o7 i+ q" J# J* u      // Get the value of the object at those coordinates) P* z- H0 r7 n0 b4 q/ ?$ q+ T( |
      int I;
, _& w1 s6 ~% l      if(moneySpace.getObjectAt(x,y)!= null){
2 G5 `4 ]4 A. I4 f, ^        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();% _; D8 I+ g3 x& a9 ~
      }
8 g* f6 m: [: N' J      else{
% K$ E8 p0 F  `( N        I = 0;. [  ?" S1 v1 E4 r
      }$ B3 T$ g/ ]3 m3 p4 X
      // Replace the Integer object with another one with the new value, h7 c' P( x/ S7 ]
      moneySpace.putObjectAt(x,y,new Integer(I + 1));; H: S7 }9 y' |+ O9 E4 g7 n; w
    }

, g' R, L2 h. x/ X( }; u这里面if(moneySpace.getObjectAt(x,y)!= null){
/ j0 B- o9 O# c# _6 _4 ]* s8 S        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
! ^( J- Y: v* g' R; \" l- L% Z; }      }
- z; @8 E* t. H2 w9 W      else{3 B+ _- s2 g" t  }- h
        I = 0;
/ o  p4 T5 z, @$ o
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
- U  {' y- G8 b+ I) \; J# b初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-17 05:56 , Processed in 0.021444 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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