设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4978|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
3 F" @( P" R4 K! kpublic void spreadMoney(int money){
, G: c7 Y; E/ y) X+ l5 n! z    // Randomly place money in moneySpace
( n( m4 d, ~1 m7 y    for(int i = 0; i < money; i++){
0 G' Q3 s5 I/ P1 v8 p- C9 `$ q# W
      // Choose coordinates* m7 R$ b0 e/ ]+ r1 x( s
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
  a/ f8 x7 ]% M  E! G" L: \5 S      int y = (int)(Math.random()*(moneySpace.getSizeY()));! l' y$ n4 e. n, l
. {* m  n/ {  g* Z1 {7 g9 V
      // Get the value of the object at those coordinates+ v2 Z+ ?' f0 D1 K# i
      int I;
" t, g& g, H7 _8 I! z      if(moneySpace.getObjectAt(x,y)!= null){
$ G7 |5 L9 c7 P9 B8 c. L+ h        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
/ k3 S! H4 D4 W8 I      }
/ r- F3 b! e2 I5 q3 f1 c      else{( F+ D3 P- M- ^
        I = 0;
9 b; f( S* N% [; Q      }
7 d/ F3 T6 ?* t/ Z      // Replace the Integer object with another one with the new value, h( H% y  t! g1 H1 @% ]+ Z
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
' ]: n% x( k2 z; D6 k, X    }
  l% D( A+ B8 K8 B* k, S
这里面if(moneySpace.getObjectAt(x,y)!= null){5 }9 w/ v0 C9 Z! c4 z
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
1 z1 z7 v/ g) r. c0 }1 R      }
* o+ R7 W5 Z7 L6 W2 d" x4 g. K9 _/ X      else{% M2 f: ]1 ]5 z
        I = 0;

1 I' b% b/ H& ?$ R是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?+ `* ~$ l7 O6 {" c5 C4 q. Q
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-8 17:30 , Processed in 0.015824 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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