设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3851|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
1 }/ t& r# s' ~7 T- xpublic void spreadMoney(int money){
7 N: r8 K' A2 [    // Randomly place money in moneySpace
; p: R; U( J+ i; \    for(int i = 0; i < money; i++){' U: P3 o8 ]4 Z! z: R

+ s0 i$ \" E; t7 S! X      // Choose coordinates
2 T, b: V- H3 K. t+ u; O2 {; I      int x = (int)(Math.random()*(moneySpace.getSizeX()));' h* j/ [  \1 K* n* W% G
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
# Q% ]* b" `) S( `7 X, a
+ Z: O% t6 a9 C! g      // Get the value of the object at those coordinates
% m5 W2 L- M7 B5 `) i* }* b      int I;
8 |% f6 [) h# D) H      if(moneySpace.getObjectAt(x,y)!= null){: g* a) U/ I, t1 u
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();; h" v1 ~+ Q  a8 n6 d3 {3 ]0 s
      }
4 t2 `# A7 i, f- Q/ X/ ~: x      else{: s; T& h( k8 H+ g0 j" ]5 {2 u! d
        I = 0;
; c0 O0 N1 f- L+ d; G& ?      }5 s' F* M, H' C5 X! K' W
      // Replace the Integer object with another one with the new value  a/ h( K3 x+ Y
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
, p2 n' S2 m* ]0 }  D    }

& `! \2 R, U8 j, |这里面if(moneySpace.getObjectAt(x,y)!= null){
: G: U$ M8 }4 y2 G0 T        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
3 F( {7 m- g* C$ g' V& C3 _4 j) q      }5 V5 Q8 G* O2 L/ |0 y) \
      else{2 E9 T8 I6 l- i) ^% t+ e
        I = 0;
+ V6 q! r; j; u# f. f) u! \
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
  U! r7 |( d( D6 c/ Q" t! p: _2 X初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-1 06:23 , Processed in 0.012059 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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