设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3870|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中) D8 G6 K3 O  ^! l8 q
public void spreadMoney(int money){
/ A7 j; J# `$ V- C    // Randomly place money in moneySpace. Q/ O7 V( U% e0 \; F, ?* H
    for(int i = 0; i < money; i++){: c6 z' d$ F8 f3 t* u7 N2 H7 R
# U0 \, J. S2 \$ @
      // Choose coordinates5 k& A  X4 Q3 ]' r* |! C' @! E; }
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
6 W2 S- z) y1 L" C7 i      int y = (int)(Math.random()*(moneySpace.getSizeY()));9 T( S( i( I' H& n

/ y2 `: i+ `1 e( i. I' n3 d' N      // Get the value of the object at those coordinates
( H0 q6 }8 M( ~. `      int I;
1 G3 X# \" O' d0 f      if(moneySpace.getObjectAt(x,y)!= null){
+ C' z  X+ i* ]' K) y        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();4 K: @0 J  Q; I
      }5 `+ n; C% n! ^! [9 W
      else{
! E' l9 {3 l: r        I = 0;
# w, G7 C) [' t4 e6 W% ~1 O      }5 Y% H/ n4 [' O5 x, b
      // Replace the Integer object with another one with the new value
+ t, m: a4 m3 h; ^' K      moneySpace.putObjectAt(x,y,new Integer(I + 1));
/ @2 ~+ w, x1 C" H  r+ c1 `    }
8 Y2 l- @& U8 A) j! S9 ?* k+ x  \
这里面if(moneySpace.getObjectAt(x,y)!= null){
  ~) @+ z4 L9 @( y+ L- Q8 V1 D        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();$ X/ B0 P9 \) a6 |9 y3 E
      }+ n3 I4 K) z0 C3 J' w
      else{
$ }. s. t, n% c7 o5 i! Z' O. k        I = 0;
) E5 |2 }  F+ y2 a0 w& L8 @4 b1 n3 w
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?, w2 i& L* X0 C" ^0 a; L# z
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-6 08:57 , Processed in 0.014045 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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