设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4004|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中# L: S0 J7 c/ y0 K, K- Z% {! \
public void spreadMoney(int money){
9 P6 ~# l( G* A6 ]. Y    // Randomly place money in moneySpace  ~# X) U$ z1 {0 }/ J5 D( a
    for(int i = 0; i < money; i++){* C" q9 ~- y: }

& U3 Z  X/ U1 L# v9 M      // Choose coordinates8 P# |4 {  y# s. \
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
$ \: q! A* Q2 i' n      int y = (int)(Math.random()*(moneySpace.getSizeY()));+ Z5 j! {. X' n* y. i
* B' D! D& c4 \3 b. v1 W: H
      // Get the value of the object at those coordinates4 e* Y- b$ X) u% i- n
      int I;
4 \  n! ^. |$ \0 w% s" s& s+ y      if(moneySpace.getObjectAt(x,y)!= null){
# i6 O) _9 M3 m3 g9 r) m4 b5 Q9 C        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
6 J* h& ~4 c, l; K" V$ [0 q      }6 s3 k) A2 H2 G- Y. j8 K
      else{
8 f. O; D  |. K) i. t/ B        I = 0;
0 E3 X8 [, r. |      }
/ z. i/ {7 W1 h8 J% z8 w1 R      // Replace the Integer object with another one with the new value
4 K9 P6 c; f7 I' [+ ^; I: d      moneySpace.putObjectAt(x,y,new Integer(I + 1));
( t: ]) g1 ^& S. F: ~9 D% V% X    }

5 ~9 {. w! K- v- w这里面if(moneySpace.getObjectAt(x,y)!= null){
/ y8 y* p2 p$ @. W( E( V, J/ o- f% o        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
# }* D1 {- G% }7 W2 Z, p/ p2 k      }
0 P4 _5 ]$ Y$ Q5 I9 T4 u. W      else{) n9 ?1 N0 P$ Y1 }: x0 p
        I = 0;

3 T0 X- U8 i( Y$ \# W# D  D是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?8 I5 h# _3 f: N2 o# U
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-8-23 20:21 , Processed in 0.014806 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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