设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5319|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中4 N1 q. j9 p( U& i. b. F( V! G
public void spreadMoney(int money){
3 s+ ^6 e- Z7 D: c    // Randomly place money in moneySpace( a( U  \0 m1 f2 Z
    for(int i = 0; i < money; i++){
. V+ G# F  S! T: i4 x* Y5 F
! O0 `7 H# t, l# d      // Choose coordinates) ~0 l8 ]% c& u  T/ h/ _
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
' r" z0 I, ]8 {' M5 q# d; R7 z      int y = (int)(Math.random()*(moneySpace.getSizeY()));1 o% l' a( s+ U+ y% a( _

) \4 J' p% V) }1 u% x+ G/ M      // Get the value of the object at those coordinates3 `, V+ V  `; B# h. c5 r" N
      int I;* I: w% s/ Q; n
      if(moneySpace.getObjectAt(x,y)!= null){; G; T0 h, {* \/ C' o' s; y
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();' J1 b, Z' v! e. o
      }& E, Z% |7 Q# M1 ]  V/ Z
      else{' d( c. A" p& |: K) R! T
        I = 0;( J8 ~& R/ M6 g1 Y  I9 b
      }3 c( H: u7 H7 n- Q' J1 L" p0 T
      // Replace the Integer object with another one with the new value4 |/ X9 {  Q) s! p
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
: j# y0 M* S: w- e7 K9 q4 }5 t6 J    }

- X, g1 y+ ]* E% U这里面if(moneySpace.getObjectAt(x,y)!= null){
* ~. d! o& j! S        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();. t; u5 A9 |$ o7 E+ a, m6 \
      }
, p2 s" k# C! e      else{
: c! A0 q) d; T" u1 D# M/ r; x, U        I = 0;
) k  y, Q0 @! {6 ^5 A8 d% m
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
6 ~0 {2 i3 I, f  L初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-16 10:09 , Processed in 0.016641 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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