设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4900|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
6 X& }* E: ~6 ~; r0 U0 n* r7 p, K/ Wpublic void spreadMoney(int money){$ Y# V$ [1 {& l* {; P& j
    // Randomly place money in moneySpace7 v- B/ s' t/ J1 z
    for(int i = 0; i < money; i++){
  s" ]! d6 y- K: G, m6 \( C; S& E
      // Choose coordinates! S  _4 A( ~5 Y
      int x = (int)(Math.random()*(moneySpace.getSizeX()));9 j: ^* }! H- |' Q7 f
      int y = (int)(Math.random()*(moneySpace.getSizeY()));* M( m8 h, x, S4 h8 P, `: k+ C4 a9 c/ D5 r
) d1 m2 L* a8 q4 \) _
      // Get the value of the object at those coordinates9 z6 o  Z$ O- z
      int I;
" k, N! z$ c) c  \( Z9 G7 v      if(moneySpace.getObjectAt(x,y)!= null){2 a: {4 n3 c6 s4 I4 [! Q
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
; U8 C' S! S! z+ ]% D      }
$ ~; C( {+ x8 _, ?+ M      else{
+ [, N+ t. F# M  T1 |8 F        I = 0;
9 ~1 ^$ @: ?2 w( Y3 W( w. R      }
' u+ t& s1 s) F' {* s+ z3 H      // Replace the Integer object with another one with the new value
* n$ Q$ a9 u% e+ S+ U: ~      moneySpace.putObjectAt(x,y,new Integer(I + 1));5 L, M  `2 C& j# n0 @
    }

* q/ f9 d0 C: D% S" l% Q4 P这里面if(moneySpace.getObjectAt(x,y)!= null){, B, e4 [, S7 q) e' ]
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 j4 n5 u8 n& e5 k9 F# k/ K
      }+ l6 S: D7 i8 N7 j# u
      else{
6 Z0 Y' N# [  b: o/ ]        I = 0;
7 N+ {% E4 _  R
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
) Y' R2 h# e4 ~1 J6 s( S初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-20 11:46 , Processed in 0.014998 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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