设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4998|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
; u& f" K8 P  z9 `$ ^6 V  Jpublic void spreadMoney(int money){
: ]( ?1 C' T7 ?  r& n, u3 ^    // Randomly place money in moneySpace( a* |; D3 A+ I5 t# E) ?) ~
    for(int i = 0; i < money; i++){
, `  d' o/ y; a- P) N4 c' a! c& z: C/ ]" h% |7 L
      // Choose coordinates
' R3 B$ _* ~+ y9 L6 A$ @. V2 k      int x = (int)(Math.random()*(moneySpace.getSizeX()));
, Q* Q3 H0 v8 f$ R! L3 }      int y = (int)(Math.random()*(moneySpace.getSizeY()));
8 y; C9 J5 Y; A* c$ Z) }. x( c  R1 ^' U* B, |- d
      // Get the value of the object at those coordinates( N: l) z1 U  G0 r
      int I;
% A$ V, M! {# b% F' X      if(moneySpace.getObjectAt(x,y)!= null){# n3 ]1 P8 K) h! U
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
$ x9 a6 Y. A  |  E      }& s* C8 k# X  h4 q4 j& A# m
      else{; k& {, q/ A) W  L. G. b6 m. ^
        I = 0;
' V5 f- m8 D# ~- {" m      }6 Y9 ?: J; B* i0 s* \$ c, ]
      // Replace the Integer object with another one with the new value
2 C8 x# w2 q- h0 B2 N% B1 J# R      moneySpace.putObjectAt(x,y,new Integer(I + 1));
2 N" B( z- M" ^! E    }
; t0 h8 z$ m+ e/ X9 b* Z/ Q  [
这里面if(moneySpace.getObjectAt(x,y)!= null){6 q! U3 y6 i% e7 d
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();, j6 D( a( l7 C/ b6 K4 V
      }
# }  V' h) R) X      else{
4 k4 m5 E6 O: d5 n3 l( @        I = 0;
1 t' R0 N# [7 |$ [/ K6 M# b
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?. l8 N' f* H) k3 C1 R
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-14 18:44 , Processed in 0.018548 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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