设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4473|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
& i/ K/ i$ ~2 I1 C- fpublic void spreadMoney(int money){  b  ^' k! R; A1 y* X
    // Randomly place money in moneySpace
' |2 D: Y- S; }    for(int i = 0; i < money; i++){
' p  R8 A/ |$ R
0 J+ t1 V3 k) u& M      // Choose coordinates2 j3 j. E, U8 S4 i( ~
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
" c& l/ m: x9 g. P% v+ L" t      int y = (int)(Math.random()*(moneySpace.getSizeY()));# ~+ j8 [# C- k5 v. R1 ^
: x0 i) C( r/ w" _3 L5 q" \
      // Get the value of the object at those coordinates
. Z% S! I# T. E  Y      int I;
/ s4 z2 R9 ~; E  o1 n. e      if(moneySpace.getObjectAt(x,y)!= null){% s% x1 `7 K+ H6 r' a
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
* G# B8 A: \4 r$ w. U      }
2 q# J3 N; Y& I# f$ e' t8 o      else{
7 e- {' B( b0 k        I = 0;
, M# j7 r8 v: K* n      }
  r3 x: C1 y3 u      // Replace the Integer object with another one with the new value* ~) z9 G9 e, ^9 S( j
      moneySpace.putObjectAt(x,y,new Integer(I + 1));) @8 A9 Q; C5 U
    }

  ^6 E  P' b0 Z这里面if(moneySpace.getObjectAt(x,y)!= null){$ @+ X2 U( [  B, M! c' k* S5 Q
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
9 ~( h( r1 f3 V      }
' o1 {* d. N$ u" C      else{
3 `  }) Q9 O7 o/ F! J& j, U4 a& x3 A        I = 0;

9 C/ S7 j+ a" Q8 z' g" a& S. H是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?5 ?! K' G3 n/ k* O1 t
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-15 09:06 , Processed in 0.013926 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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