设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3903|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中. ~; l5 q% }4 x. y( J
public void spreadMoney(int money){
0 s5 F/ c' ]1 l5 |2 \; O8 s    // Randomly place money in moneySpace: ~# Z1 o% A  N8 P$ P: R1 N2 D" w$ Z
    for(int i = 0; i < money; i++){
# m3 R, W. n. {; F
. h, _+ O6 `( v( E' G# Y      // Choose coordinates, u- Z; I1 w8 Q/ H: A, T$ W
      int x = (int)(Math.random()*(moneySpace.getSizeX()));* j& `4 i5 M* ]
      int y = (int)(Math.random()*(moneySpace.getSizeY()));4 j/ N, w0 m! W4 t. Z
" S/ e) `9 P+ f  R; O$ }. n; H* \: Y% x' z
      // Get the value of the object at those coordinates' X/ q8 p/ u  U* Y  J6 ?+ V( G
      int I;
( f) c2 [  G, W- M4 \5 ?/ b9 D      if(moneySpace.getObjectAt(x,y)!= null){, Y" x! I( ?2 L
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
8 }. R' o7 q$ O/ Y9 U      }2 C- q* B( S! F' S* p/ h
      else{
; F' e2 N0 I3 {& L/ z0 R. {        I = 0;
; s! W9 w5 `2 ]/ Y2 X+ k      }
. [/ Y) ?7 m; @% `      // Replace the Integer object with another one with the new value
6 ]+ [4 v3 l' M      moneySpace.putObjectAt(x,y,new Integer(I + 1));
* `0 n4 t; ~; H    }
. R5 N5 R9 E, x& {
这里面if(moneySpace.getObjectAt(x,y)!= null){
' [* _- t+ I# e3 ^3 T        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
7 H% s  J7 k+ n. f' L# W+ j7 ~9 e      }
* R& i' a% X% I) C# R7 U      else{
  c6 H, W; [3 e8 l$ a! H        I = 0;
1 l/ E) T& U: ]) q  _* ~1 [. R$ d
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?6 v. ?4 c5 H7 b: z' z. l% U5 h
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-17 06:47 , Processed in 0.030178 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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