设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5362|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中+ b: l' b( ?8 o1 d: z
public void spreadMoney(int money){7 p8 y4 c9 F& Y) F
    // Randomly place money in moneySpace2 S8 l" s3 P/ h+ Z6 U. k
    for(int i = 0; i < money; i++){
( ?. j- a5 |+ F3 ~' i! G1 Q+ F7 z0 A! B+ x
      // Choose coordinates
0 O. H) ?9 K) V2 o* y( p& f4 X      int x = (int)(Math.random()*(moneySpace.getSizeX()));9 ?' I* N; T0 h0 B1 W
      int y = (int)(Math.random()*(moneySpace.getSizeY()));6 D; D3 O: J6 C1 W1 a8 ?9 ?' J3 }  S6 O
3 Q  o1 o- T- Q0 l/ D( A
      // Get the value of the object at those coordinates
% j* |8 D/ V* o. `& n  D/ S      int I;
7 r2 |+ T" `! t      if(moneySpace.getObjectAt(x,y)!= null){
+ E% `9 F8 O- ]        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
1 }. d# G6 Q( N' l1 A      }
+ D, F. r2 ^# V7 ?( S% K6 O      else{
$ B$ X6 e7 r$ u# _, j0 z. c5 ]        I = 0;
) b! W1 B8 r7 d      }8 q1 j' n7 z! N% V/ J. a
      // Replace the Integer object with another one with the new value7 y3 i+ D( M" I9 ^/ H6 L7 e
      moneySpace.putObjectAt(x,y,new Integer(I + 1));! E5 n/ q/ b0 K
    }
5 F4 G* b3 {. ]6 E' ]4 G; H, a
这里面if(moneySpace.getObjectAt(x,y)!= null){5 ?8 b. K) @3 ^$ ~8 Y
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 a- y9 ?; ^) S: N: D5 g2 k' l- c
      }
7 R& U; Z% j9 M2 X      else{
' O4 q& b) r0 ?" I" @  [        I = 0;

" G5 {0 J1 |' i; O! H是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
; J3 R) [; @- |5 w) e初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-4 09:42 , Processed in 0.017505 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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