设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4756|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
% J9 y1 d* `; E" D* E% |public void spreadMoney(int money){
0 P, O. l" B& j    // Randomly place money in moneySpace
' i, u, R8 q0 f; k% l    for(int i = 0; i < money; i++){
, }1 O6 X# U- _  [! s4 C6 L( v+ V# G9 v/ f: I) R
      // Choose coordinates
1 j; ?$ o4 l* C0 x! e      int x = (int)(Math.random()*(moneySpace.getSizeX()));
7 h* P7 |. }5 g+ u( P+ x3 v0 X      int y = (int)(Math.random()*(moneySpace.getSizeY()));: d* u* d* C+ B

5 l+ ~3 k9 A0 Z8 D3 O6 I      // Get the value of the object at those coordinates; o* q* g! |) j: m1 w! M7 F
      int I;
6 j6 s" _) }1 w# P7 o: a8 L      if(moneySpace.getObjectAt(x,y)!= null){: C) G' }6 z, q4 i$ ?" c# g
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();# x: {2 @' Z. U( _: _5 \6 ?  V
      }
6 c7 e" W+ m% _2 \- |9 w      else{& \: F; b- \4 J( i
        I = 0;
8 H1 N5 F: L2 q5 e* E; ^      }' I# }, _& G' g; ~" T
      // Replace the Integer object with another one with the new value
' X) G/ E# O: d+ X/ c% ]9 e  T6 |$ @      moneySpace.putObjectAt(x,y,new Integer(I + 1));
! R3 w: N7 n* h    }

) {* M' d9 a- z5 W2 n这里面if(moneySpace.getObjectAt(x,y)!= null){# n6 x; q# [" K" h% k# g! [
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
5 Y" q' I* U1 m2 `8 p9 C      }
4 x& I9 Z  a6 A1 v1 |! ~: z( t      else{
$ s2 N- d2 A' @" p8 H+ L        I = 0;
( w& l1 h" U, V+ q
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?# T# Y6 Q: c8 P0 [; K' n2 Z& J- {
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-12 17:09 , Processed in 0.014097 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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