设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3886|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
. J# F; i% n& C& mpublic void spreadMoney(int money){- U/ {2 m! w/ T, l* Q8 t
    // Randomly place money in moneySpace
9 k% l! K& q0 d5 j    for(int i = 0; i < money; i++){
7 B4 Y4 z8 t, D5 G6 M
! g6 t" m& {* F; w  @, u7 k3 F      // Choose coordinates- q1 h& T% N2 J' n2 f
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
  X1 y0 P  U. b6 [5 a      int y = (int)(Math.random()*(moneySpace.getSizeY()));
6 Y: v- d% K" a$ N, l& v  A+ z) W( |, u5 q. R
      // Get the value of the object at those coordinates
7 F% ?. U8 m% W6 g' \      int I;
& s6 o4 b6 I. C$ I0 r- M* p1 d7 d- ?$ g      if(moneySpace.getObjectAt(x,y)!= null){
- u5 M/ B4 u4 l0 X& C9 N# R0 d6 N        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();1 |* x. Q7 Z+ K* `* e* P
      }
8 f9 ~) u2 l" z3 I3 R( |% _/ t      else{$ O+ V/ M5 b( M2 L
        I = 0;7 N7 u' A% Z- V" M. o7 v
      }! O; k+ J' k2 B. K$ Y- K; N
      // Replace the Integer object with another one with the new value9 I. `/ d; p, U  g! N, ~; ?
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
! H  _6 m; e! ~    }
% X" O8 h$ N  ~- B7 z3 T5 C% g0 C
这里面if(moneySpace.getObjectAt(x,y)!= null){
9 R& d1 Z$ Q9 m/ M+ o4 @: h# G! F$ k        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();; x7 s; I" l2 f3 h" {
      }
/ P7 m3 q% b9 u3 N7 J4 D      else{
( w2 B4 f( c8 \: I3 ~7 p        I = 0;
! F( t+ @* D! ^  u1 M- {. ]
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
5 y5 R0 {; H$ V3 I% T4 G) @初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-11 10:59 , Processed in 0.015623 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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