设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5426|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
/ j/ L6 H9 L# _public void spreadMoney(int money){
* n7 t# G0 x4 H& J    // Randomly place money in moneySpace. X1 f1 |) O4 L$ g: S
    for(int i = 0; i < money; i++){6 R. s* @. `& L1 u- w  y6 v" [
% S4 g9 q9 l  b& g1 W  \# R
      // Choose coordinates
" X. @3 n# u( v5 E; {, I8 I      int x = (int)(Math.random()*(moneySpace.getSizeX()));* h. l' H/ b, ?$ Y" s  t! F
      int y = (int)(Math.random()*(moneySpace.getSizeY()));( x6 S4 |9 F# G% q) ], b

; O9 [2 ]* p% g- b' Y  M      // Get the value of the object at those coordinates" n7 A' J- ]& {1 W6 `2 K
      int I;# j) h, c& }1 Z1 Z
      if(moneySpace.getObjectAt(x,y)!= null){" r' i4 l# a9 F
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();6 j, u$ q1 |/ }
      }
8 ?! `4 ?" n  {; M" n- |; {' M      else{2 ~+ h" c' ?7 r5 _* I# B
        I = 0;
. Z# O: R% m$ ]- Q9 I      }
- u' t; v% k0 m+ H2 c      // Replace the Integer object with another one with the new value1 @+ w/ ~: \* Q1 M, Y" J
      moneySpace.putObjectAt(x,y,new Integer(I + 1));* ^  |8 A& r' `
    }
' }1 ~4 t/ T5 {& v3 n
这里面if(moneySpace.getObjectAt(x,y)!= null){
) c+ C: p6 }/ Y% h9 K  k        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
) L" k! S: h0 P" K% O! A7 K      }
7 L. t1 |2 w- R  d& b& `      else{* y+ o$ c% j8 x# M' H$ K; x* C
        I = 0;

6 M  [$ {6 m; u+ @7 R; j是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?* T& X! ?, D2 G8 ]# W$ g; b! ]
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-17 20:28 , Processed in 0.013661 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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