设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5118|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
" p4 `) p: E+ H7 e1 V6 |8 Xpublic void spreadMoney(int money){
: G1 v% Q: @; }    // Randomly place money in moneySpace) y/ k3 f7 p/ L3 O
    for(int i = 0; i < money; i++){
. @5 s- y6 J* G6 |4 B$ p
1 m& l" ~1 A% S) g      // Choose coordinates
+ x, Y. \- n" N( K* y      int x = (int)(Math.random()*(moneySpace.getSizeX()));- p% Z, m, \1 v7 `& t5 k* Y  B
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
# I' r, q4 i" p, H4 q% Q7 o6 Y0 I3 g7 t# Z; G& L2 u
      // Get the value of the object at those coordinates
  k3 C3 z/ j2 L( p( \0 [, ~2 `, c: P      int I;9 O$ Z2 Y! Z1 A) }
      if(moneySpace.getObjectAt(x,y)!= null){# {9 ~1 P( p% p# H
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();( L- _' o3 `  S7 k0 Q. A7 b& z+ K
      }
% h4 `0 ?6 }6 q& ~: E, U      else{; I7 l7 ^* Z% W( h6 E
        I = 0;
3 F7 v; I4 V4 e) x) j      }- S" Q( ]# O3 d+ I* N7 o
      // Replace the Integer object with another one with the new value6 G$ K& E1 ^5 M6 V
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
# Y. |* G  I( _( U: v( M8 b6 p    }
& i/ M0 Y9 d2 a1 \2 ?. F" g& \
这里面if(moneySpace.getObjectAt(x,y)!= null){
5 N( r0 O0 z: U# [) S, R        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
+ W  E; P4 ~( b; [; E      }
( \8 j( a; h7 s, l4 P# k! g      else{5 e0 x: S+ i0 ]5 Z7 }  }- L
        I = 0;

" X2 Y. q. D7 Q7 C/ r' x是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?9 B) U1 h" e9 t
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-3 02:34 , Processed in 7.672085 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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