设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2695|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
* D" P% x9 m$ S2 ]public void spreadMoney(int money){
4 T. V3 z3 w' ~7 ^    // Randomly place money in moneySpace# `: Y+ q+ \; N5 h
    for(int i = 0; i < money; i++){) }# r& F$ D3 A5 c
9 C. S+ S1 m! ]3 N
      // Choose coordinates% k/ y. p  o/ s! |
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
7 L& d1 Y2 G3 A/ t* q3 Y" c# }- T      int y = (int)(Math.random()*(moneySpace.getSizeY()));8 c" j/ P( {+ a2 ^
( l+ H( e5 C) w" c
      // Get the value of the object at those coordinates4 G) @) n+ S" G* N! ?3 M( g
      int I;
( y8 {' h1 e' a" l& a, O      if(moneySpace.getObjectAt(x,y)!= null){
( R' J5 i1 Y% L6 J) `. r        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();6 s) u0 C# C$ `/ `/ y
      }
* X, z9 r2 L& r0 l/ M: w      else{2 G! k, ^2 C* _( Z2 J+ p7 b; U# F1 q
        I = 0;
. w- _. h2 J0 v% @3 b4 S      }/ ?8 N9 T5 I5 i) `5 l6 p) b
      // Replace the Integer object with another one with the new value8 X2 h5 `+ H' J4 F* e" I) b" E! E
      moneySpace.putObjectAt(x,y,new Integer(I + 1));( j' t" H+ p/ W) M) w! o
    }
0 l. j; \" m. n+ }0 I1 v8 Z
这里面if(moneySpace.getObjectAt(x,y)!= null){
$ x( ^& h8 k5 Z        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
1 |3 k1 f* g0 a9 u9 y0 Z! N# ]      }
0 u; x1 \: c# l3 |; T. W6 |      else{
/ j6 ^- P) X8 S- C# {        I = 0;
$ Y% L( {3 P: {! y# d7 r- ~& m
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?( E" c8 f' _/ [9 W, F
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-9 03:29 , Processed in 0.012290 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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