设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4338|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
  u! y' n# k$ J* ^' R" a1 Ppublic void spreadMoney(int money){' G% `# V5 n. A1 I, ^7 H
    // Randomly place money in moneySpace
4 }; x( ]* [% l$ H    for(int i = 0; i < money; i++){
" s1 z/ X& z1 [/ h5 B% s9 a; t) l5 E7 m& S9 g
      // Choose coordinates# r5 o4 ^/ y$ v9 z
      int x = (int)(Math.random()*(moneySpace.getSizeX()));: o' b; @% X/ [+ e* q
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
. S) e* ?; F0 M# H2 e% ~
( k0 s" ^: B" @4 L      // Get the value of the object at those coordinates% k. \9 y* k3 Z4 a0 @5 H
      int I;
$ X. z; S* x, j$ ?4 t6 g$ `      if(moneySpace.getObjectAt(x,y)!= null){& `7 M" `6 }: b2 z8 _
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
! a( k9 H" x! N3 [2 E1 c1 \1 h' |: f6 a      }
0 W; j3 a" J5 Y6 c; ]      else{
# r3 b- m2 ?8 l4 ?  I7 B; e& G/ S/ D        I = 0;
" ~( r: ~8 ~. I( l' ]      }
; L5 c% h5 i* w) U      // Replace the Integer object with another one with the new value" n4 ^1 R6 h9 q0 k
      moneySpace.putObjectAt(x,y,new Integer(I + 1));7 E, [( q) _1 i( l
    }

/ S$ `0 A* ?' n$ o+ W: q6 L这里面if(moneySpace.getObjectAt(x,y)!= null){
- I0 `0 U4 j# k        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
) N% i$ L! h0 D! p! ~* M      }
! e/ n4 w5 l: d      else{
' o1 N& ]; q, W& o: A( g# j        I = 0;
- k6 i: u! q* w$ |
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
4 n; [% Y9 |. u) x$ |% N; P1 d' D% l初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-8 23:53 , Processed in 0.015006 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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