设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4407|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中: T7 Q7 [; _- I2 G
public void spreadMoney(int money){/ i- N2 z+ G/ h1 ~
    // Randomly place money in moneySpace
5 I/ J8 F0 K1 Z0 `% g0 W! A# J! d    for(int i = 0; i < money; i++){9 q+ t4 [* D2 S5 h( d* d

8 f, d5 p- g5 P4 b      // Choose coordinates5 P# C+ \  q1 E( t' G
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
; `# m5 a. ]' z: z# x+ {! k      int y = (int)(Math.random()*(moneySpace.getSizeY()));
  D- z9 f' ^  r. t; n8 }; M& c) ]% q  m" i" m% W% j7 W. f' ~/ t
      // Get the value of the object at those coordinates
9 i5 Z. m5 C9 p7 L( S      int I;8 [1 {4 o% V6 h
      if(moneySpace.getObjectAt(x,y)!= null){
) v) Y7 A" ]+ m/ V* @        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
' D2 j4 z, S; b2 {% ^      }* j$ o$ F& o( F3 Z) Z4 _
      else{, W: ~$ u  l# J) W/ V
        I = 0;
8 q. V5 f. o; u+ i+ e      }
# ~* N1 o5 O" ]' l! x  F& T( D      // Replace the Integer object with another one with the new value6 q, k% b! y0 i: W
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
7 `+ ^/ B  G/ B+ u# X  w    }
0 T) [9 s% {, o# N% M
这里面if(moneySpace.getObjectAt(x,y)!= null){
! B6 E+ X! L  A( F% B7 q        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();- B% b2 @! L$ l/ S, A
      }
2 ~. r- D( _4 _( a+ b1 g1 c4 Q4 n      else{+ f( x" H  i; U, \7 X* M! f
        I = 0;

" ^( ^- W+ q; t! s$ {' M  e是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?6 a3 N" x& f( l; j
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-22 18:54 , Processed in 0.017024 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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