设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5251|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
: ?0 t) O6 R+ P4 Z( {public void spreadMoney(int money){
/ f5 r' L' Y  `7 ^6 P3 n& X    // Randomly place money in moneySpace
2 s* g! p% ?7 b$ E9 Q3 O    for(int i = 0; i < money; i++){/ k% S) T. d# m! [
0 ^4 I& c/ r6 q- F
      // Choose coordinates7 z1 k  v. M/ {5 J
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
( f) l6 D& X7 f, k$ f1 L      int y = (int)(Math.random()*(moneySpace.getSizeY()));) V) P" x, G3 o* |. a
. Z. r; O9 j5 G' |! t& Q6 T
      // Get the value of the object at those coordinates
8 i( k$ u- h0 I+ c; X1 m0 r      int I;$ N% l/ e8 V; F; A+ v0 b8 x+ e
      if(moneySpace.getObjectAt(x,y)!= null){
* t( d+ s% I8 b' f1 K* }; k# T        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();' h( m$ C9 g! q" V7 _
      }
; n3 y! w+ `- {$ P: u5 G: r0 ~      else{; |% y( v2 Q( b1 c3 t- g% u
        I = 0;' y4 N( H  Q+ ~+ n2 C- C  J* h% d  g" `
      }& o) Z9 B1 I; v0 Y8 J8 |
      // Replace the Integer object with another one with the new value
0 `, ^% M9 Z9 S+ q2 S: y      moneySpace.putObjectAt(x,y,new Integer(I + 1));' F6 ?2 B5 D+ f0 i4 X4 s. _
    }

$ O' W! m$ s9 }7 `: O1 r5 C这里面if(moneySpace.getObjectAt(x,y)!= null){& x% S3 a: P' g
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();/ u, N; G& f* x! G5 o- C
      }
" T2 U( B- q0 V+ }* Z; Y% t3 ~1 v# Z      else{0 d. \: Y4 ]7 q) S
        I = 0;

; b% h$ D: d1 }是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
: _. c- k5 h0 J; r7 v% T初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-1 06:01 , Processed in 0.016604 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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