设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5055|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
0 f* ]- z! L+ N8 T5 Ypublic void spreadMoney(int money){
$ h2 @7 {/ Y3 W* Y4 o    // Randomly place money in moneySpace
3 b) v: l+ L* N    for(int i = 0; i < money; i++){
+ x0 N/ C# u5 U% V% o
% e1 W; y* d: v0 x& F3 j      // Choose coordinates
* I$ _1 N- Y+ j/ p5 S      int x = (int)(Math.random()*(moneySpace.getSizeX()));
  B' t2 }' K% y$ @! F# [6 |1 v- m      int y = (int)(Math.random()*(moneySpace.getSizeY()));
$ N) V6 X* A: V" v) U: k
4 K) o9 T* l- J! m      // Get the value of the object at those coordinates! x/ @) u6 e0 A/ w5 A$ M
      int I;
; ~1 e9 p! C( h$ o% u# q5 y! m      if(moneySpace.getObjectAt(x,y)!= null){
1 M4 d2 C+ q# c5 L$ O2 t5 |. K        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();" G& y' x+ S& T# Z  v" R4 P  ]
      }
1 c3 G% f+ G. e* h      else{9 j2 O, R7 O$ c' \3 ~/ P  x
        I = 0;
  y" T9 _" P5 D' E& z+ b      }% H3 F! v( {5 p6 i; _: m* p- Q% H" s
      // Replace the Integer object with another one with the new value% ~: q: Q" ?2 x1 ?
      moneySpace.putObjectAt(x,y,new Integer(I + 1));* F% A% J& M: c% ~  M6 e$ P5 w5 p
    }
& @8 _) m2 _' C  R; k" D) Q* @
这里面if(moneySpace.getObjectAt(x,y)!= null){
7 y6 r; H2 ^$ I' }        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
# ?: r' p% J9 b/ J/ o( {      }8 Y& [. L. k1 @0 n4 U4 z
      else{
* [! U$ m- l0 X        I = 0;
$ Y0 ]8 \& u, ^7 j% ~, c
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?0 V9 p/ y; d% Y* g: \& X! \
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-11 14:39 , Processed in 0.013534 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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