设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5361|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
2 ?9 O6 n( N$ w: @8 G' dpublic void spreadMoney(int money){
* i* Q1 n1 J) H! |    // Randomly place money in moneySpace; R1 Y- _4 H# |6 ^$ ]/ C
    for(int i = 0; i < money; i++){7 c1 R3 i3 I) p5 a

  x  M) x3 k- _, H2 E      // Choose coordinates) v( C8 c& @, N* Q: A1 F: k3 Q
      int x = (int)(Math.random()*(moneySpace.getSizeX()));( s3 s  \" d7 {( x! m
      int y = (int)(Math.random()*(moneySpace.getSizeY()));( X: [1 z  u% j" [9 r- I5 D

4 R/ m3 m8 l# U, T      // Get the value of the object at those coordinates
# |+ Q& V) S8 a2 b2 I      int I;% s4 c& }' U( k3 }: j& ]
      if(moneySpace.getObjectAt(x,y)!= null){
, B& H- G  W9 `. E0 h/ P        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
; G4 g! e4 J6 R      }
% g9 c6 c# V' `" p1 A2 n% d      else{1 F% h  `2 ?9 N5 i
        I = 0;3 R$ ?2 P8 r0 f' g! H1 x% g1 m6 y8 ~
      }' j% M- M; T& s) F0 a- n
      // Replace the Integer object with another one with the new value5 ~. Z" _4 d: o! t/ u+ t
      moneySpace.putObjectAt(x,y,new Integer(I + 1));9 t4 [1 w4 G0 e9 t1 o) _
    }
$ j! w* t3 t( z% K, m2 c) F# w
这里面if(moneySpace.getObjectAt(x,y)!= null){
) C! i$ k- s7 D& n: f        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();6 e- D! t! b3 K: }% b
      }# t5 \' [5 J$ B* _
      else{, r' d) |" u! r, J+ X" D' C
        I = 0;

5 I; T7 [. S' s: r* O是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
5 a- M: L/ k% w初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-3 19:15 , Processed in 0.018108 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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