设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5491|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
: T. Q% C" b( x+ r- k$ Apublic void spreadMoney(int money){9 @/ u# g; M. T# R7 p7 N5 O# Z
    // Randomly place money in moneySpace
" Q* G( }4 R- P4 z3 l; R9 a    for(int i = 0; i < money; i++){
4 T  X0 c  e9 z) t2 c2 v/ i6 U$ G7 G6 ?/ r
      // Choose coordinates% Z# T" h* w9 a  M
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
" N' f8 e! |% `' K. g% N* V+ h      int y = (int)(Math.random()*(moneySpace.getSizeY()));
! t: }  b- r& V, U
  N% G4 I# _9 [7 e; e# Z4 r( l      // Get the value of the object at those coordinates7 x8 z: F1 F6 u) U: A
      int I;4 T) Q  O# f1 z. v; D( ~
      if(moneySpace.getObjectAt(x,y)!= null){
5 t8 a. Q. S, H4 ~/ h& a' B        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();3 ~: M/ h, Z2 Z( F
      }
+ H7 h2 v7 Q( F6 S2 ~, S2 c5 _      else{
% W: ^1 O) b7 Y: V  a3 z2 N9 m        I = 0;1 Q: C' E3 N4 A; F0 L; H8 ?
      }
6 `# T, w, V! P; m; e9 W      // Replace the Integer object with another one with the new value0 U4 M( X; A( [( f8 R9 B
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
9 t1 X% v2 p) R8 ^& x    }
* {* F& k1 `5 f$ T: k5 h
这里面if(moneySpace.getObjectAt(x,y)!= null){8 R# f) a3 s/ j3 T
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();* g) [& s- y8 i& Y) B5 A/ Z
      }
$ t, s5 b+ ?* D8 P, [" L) C1 K      else{
0 f  K! g+ E7 ?7 X1 }/ F7 }2 u7 q        I = 0;

+ A4 u& a% F. _% w1 R% c/ M是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?, p# E" N8 |( z& i2 @( |
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-25 19:42 , Processed in 0.018562 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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