设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5286|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
! ^' _7 ]2 L! z+ N/ Spublic void spreadMoney(int money){) I+ ^% ^4 M  y' Q2 B+ V4 y3 o
    // Randomly place money in moneySpace8 x, j- ?0 O9 m, T
    for(int i = 0; i < money; i++){+ G  x  u  l$ u5 u( P

1 |' o' }5 j) Q# g9 @( ?      // Choose coordinates3 g4 ?0 k) H% _# \( u7 P( H. [
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
% ~: A: R% @2 y$ [: u; _7 l      int y = (int)(Math.random()*(moneySpace.getSizeY()));# t/ R6 ^- x; p6 l& h

; Y1 w3 s3 I5 C9 o1 z" q: J      // Get the value of the object at those coordinates1 F* [7 \; J: Z- n
      int I;8 w, x& t& S" C% ~( [; r
      if(moneySpace.getObjectAt(x,y)!= null){! u0 w* N7 _5 m; c+ d' d) w& i
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();7 a' X, G* s, c& X. ?% o9 x8 p% W# {+ F
      }. n; s5 x+ T1 x2 O
      else{2 S& T4 O- _3 o* T
        I = 0;9 w7 V# z- e% H6 S: {
      }
8 {: S& t  [7 E0 f      // Replace the Integer object with another one with the new value3 Y3 ^8 I: ]- K
      moneySpace.putObjectAt(x,y,new Integer(I + 1));  Z& \/ x( ]) U! I2 [3 I1 @
    }
! I# z8 x3 ]& p7 O  F" H* A
这里面if(moneySpace.getObjectAt(x,y)!= null){
5 t$ [' `2 K* K        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();* h4 j/ d5 g7 u
      }
' ]6 I0 A& @. p  I+ N      else{3 ]# A1 D7 o; I  K
        I = 0;
2 a6 l' @3 F( O# X
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?" X, D4 R7 N0 A- C
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-6 17:22 , Processed in 0.014304 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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