设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3240|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
  H6 w' m2 y7 Y* Apublic void spreadMoney(int money){1 {. J/ r2 l7 f! L$ n% L: n
    // Randomly place money in moneySpace6 d# b8 V9 [; s8 o0 X& E
    for(int i = 0; i < money; i++){8 a- Z- H: ]4 C$ @& A. h
* c6 [) V) s9 T. n" @# k: K
      // Choose coordinates$ E8 K& r- U6 l4 f3 h# x
      int x = (int)(Math.random()*(moneySpace.getSizeX()));* \/ l# v* I5 l8 b: J! f. |' S
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
0 t( F$ {% R6 m
- d* w$ b5 n* c: D      // Get the value of the object at those coordinates! s2 {. W  m9 u: [( ~7 p8 B
      int I;8 K) R* Y( c6 t6 y
      if(moneySpace.getObjectAt(x,y)!= null){4 e/ g: Q' q  R1 b% k
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();: w- f7 ^1 c; d: V! D
      }7 r' _/ j' j" B& N! ^
      else{
0 G/ c# C/ |% o. q( e        I = 0;% f2 r- M9 D) P9 z1 V( b- u* f
      }
: K2 G4 ^6 B$ y! d, D" a- U+ ~      // Replace the Integer object with another one with the new value
5 o- m3 W6 y0 Z8 b! @% ~: q3 m      moneySpace.putObjectAt(x,y,new Integer(I + 1));
! P. I! }; N  ]- b" S+ N# H    }

- {2 V, k+ {3 ?, L这里面if(moneySpace.getObjectAt(x,y)!= null){- D, P$ C  t/ U1 F( ^& A- J+ ~, N
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
* u+ c( H  e6 y0 g) Z4 ]" H0 Z      }# m, J0 a1 g( G% O6 y
      else{- b+ @3 L' J* b1 j; }
        I = 0;

/ N! x' `) P9 ], `是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
" T: ~, B  j1 u3 Q初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-2-8 17:24 , Processed in 0.014339 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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