设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4581|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中% `5 {- @* D9 x! ~- Z& Z# _
public void spreadMoney(int money){2 y" m* `  M9 Y; G- l! t
    // Randomly place money in moneySpace
, U. H, G+ t, j; |. `    for(int i = 0; i < money; i++){
0 s0 w' ~" }; I. \! ^/ Y+ p
3 L. h2 H0 s0 L; O3 D! X      // Choose coordinates! r8 P" @/ }! m
      int x = (int)(Math.random()*(moneySpace.getSizeX()));, L+ M& }& k( k
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
. Z" o" d$ O' h& E0 F: H& v2 v
, C* F$ M4 G( R* c% ?7 Z! x      // Get the value of the object at those coordinates
8 t% E9 O2 v: _9 B( t  W      int I;
/ S; }% {1 {6 m) w6 L  F/ ^' z) y6 U      if(moneySpace.getObjectAt(x,y)!= null){  [1 _1 ~$ k# F# n$ p
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
3 T$ x7 [. Q7 t( k! l      }! B; V$ {' ?" ~4 q" i
      else{  d8 _! v6 j7 @! E0 k
        I = 0;
: E3 b6 b0 S" u& \9 Y      }
9 Y. R* z* @9 K6 P+ g6 n" b      // Replace the Integer object with another one with the new value
% Y1 U4 q1 D( p$ P      moneySpace.putObjectAt(x,y,new Integer(I + 1));/ k( j% h! Q, e1 H6 m* K6 D
    }

# n6 k* Q7 F3 w$ _7 c这里面if(moneySpace.getObjectAt(x,y)!= null){
9 c  c' m7 ^2 u0 l* E  }        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();5 t% n4 K" C* u$ w* ?, S& w( c
      }
% M( r5 B2 b. R* J7 |      else{
/ V1 H% I3 F4 n        I = 0;

2 n, I: X; g$ ?$ Z# j是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?4 O1 l/ e, f% q; r: }$ z; D
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-20 09:23 , Processed in 0.017959 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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