设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4488|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
$ L0 t& w9 m& s" v6 ^( T1 |) N! Ppublic void spreadMoney(int money){
6 ?+ v# i: w" o! w2 e    // Randomly place money in moneySpace
* }/ A, `8 a9 c    for(int i = 0; i < money; i++){* S" G0 _& Y3 E
' M" C8 ^; F# Y' g  Y2 V5 y# P9 I
      // Choose coordinates
, _7 `% j: r8 V* p6 }      int x = (int)(Math.random()*(moneySpace.getSizeX()));. K$ B/ z( G  v. B" K& z: J* P
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
% v; r/ s4 y& a) P* x) p
+ v  C0 M* }- r: ^8 E      // Get the value of the object at those coordinates
% Y6 N# B6 G8 f. Z& G8 n5 A+ Z      int I;; Z; W, \  A( w3 @" o2 Y
      if(moneySpace.getObjectAt(x,y)!= null){
) d4 |+ a& x( S/ `1 n        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();6 V9 R$ e4 R: }
      }+ u2 ?5 ?* r' F, c
      else{
2 c, y2 L$ G9 N$ z6 I1 H        I = 0;- \2 ^, J( p8 U% n2 L
      }3 J+ I1 v1 I1 B$ Y' X' x
      // Replace the Integer object with another one with the new value! S# P5 G* ?/ O" |! h
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
) C9 |5 z% j6 {0 o0 H    }
9 D6 w- l; W5 u5 b( D$ b2 S! _4 O
这里面if(moneySpace.getObjectAt(x,y)!= null){
2 o  @. U) s* P5 y4 C3 p5 m2 v        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
8 j. p3 o: h' a. L: N% ?3 I      }( D% A; \( @9 H3 J4 E. f9 @
      else{
& a8 o8 C9 x, n+ {* ~- S        I = 0;
$ p/ H. L; _, `! I# X, y$ y
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?: Q4 D& J( ?& e
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-17 20:46 , Processed in 0.017698 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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