设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4242|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
& F- u2 e0 p) d# \public void spreadMoney(int money){
% |) J" i) [( l+ R% X3 [    // Randomly place money in moneySpace6 l2 J3 G5 k+ h. X8 J1 e7 F
    for(int i = 0; i < money; i++){* |% W. W& `3 n* e8 R! N
" o' \  X; ?' {) G- {0 S
      // Choose coordinates/ k  G; i7 {4 I, \. W6 u. V
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
9 |7 D4 [  l2 {# O9 ^5 \: {* f# t      int y = (int)(Math.random()*(moneySpace.getSizeY()));8 l  F, ^; ^* j4 P! P5 H/ s- X, r4 ]8 \

/ r% i1 t. b3 M' A2 h% P" l: ^      // Get the value of the object at those coordinates0 `' A' u: A: \" b) }0 X
      int I;
6 O: [) D7 r# g4 p) F5 ^      if(moneySpace.getObjectAt(x,y)!= null){
* S  w8 ?1 f/ K2 Z        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
! [) J; U) W  z) _5 [/ M; K  m      }
7 }$ B/ }4 ^0 F1 Z9 e      else{. T3 P5 I" B# l" Y# k3 K3 o
        I = 0;
' {/ m* N; P) |& |& l! P      }- W! D7 {% q# A" [$ m- J# |+ F
      // Replace the Integer object with another one with the new value' {1 a0 Z0 F) Y+ y6 C
      moneySpace.putObjectAt(x,y,new Integer(I + 1));  a# a/ s/ d( l& R* [5 |
    }
" _- D; A# {/ j8 J
这里面if(moneySpace.getObjectAt(x,y)!= null){
! |1 b/ |( H5 E  _4 M& T        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
0 Y: X7 Q1 m4 S& C      }
2 T' b+ s( d) n, e# l      else{
9 j# K! I  a" E! E8 }2 O        I = 0;

7 g4 ]! U6 h: [* T! g是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?0 J" X% @- Q' F" q7 `# q- I' g3 x
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-21 18:59 , Processed in 0.016027 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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