设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4830|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中% g! O; c0 T4 o+ U- z3 a5 V8 `; n
public void spreadMoney(int money){6 g; B- H3 K# Z$ J
    // Randomly place money in moneySpace
% V3 o( Z7 I6 t% F    for(int i = 0; i < money; i++){
* C1 N- E" B3 ?2 [% y, b: v% I/ R7 m, T/ p' l/ O" S7 t
      // Choose coordinates
! \3 f" B0 }% i& K- L, O      int x = (int)(Math.random()*(moneySpace.getSizeX()));3 _& D# [9 \! k1 m; w* w
      int y = (int)(Math.random()*(moneySpace.getSizeY()));5 x' u$ e6 Q/ v% O
4 _( G" n8 Q+ |: B  Y& r4 K9 K
      // Get the value of the object at those coordinates
3 I9 y3 X/ [+ ^# R& `6 Q      int I;; I8 a# o% r! ?& R
      if(moneySpace.getObjectAt(x,y)!= null){! a( l+ l# p  w+ D1 d7 r
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();+ o2 K+ T+ \5 v# n* i
      }5 T# L7 i; x( H. }
      else{+ n4 t: F7 r8 R
        I = 0;
" c: @, T5 ~/ ~2 K# r6 s; R0 H. K      }5 h$ ?. f" h( z/ U+ n) Q
      // Replace the Integer object with another one with the new value
2 C7 A. O; w  L1 @8 ?0 _2 k      moneySpace.putObjectAt(x,y,new Integer(I + 1));
' R+ ?& w. ~+ B2 p9 c& ?    }

; O4 z1 F' P9 t* H1 U6 b这里面if(moneySpace.getObjectAt(x,y)!= null){! ~* f' c9 J5 P! H
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
" F1 u  p! g  Y# l+ x# a  C$ o      }9 t" |6 }; Q! L8 ~5 W
      else{* z0 M& D  E; P3 ^5 ^, g# A% k3 {
        I = 0;
9 k' W* N9 B" E# R8 Q
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?5 J5 ~! f5 E5 a0 w- a8 z) l
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-3 04:13 , Processed in 0.017553 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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