设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5014|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中4 e& }9 J  B; j: G1 y
public void spreadMoney(int money){
& o# [4 g  M3 |/ e    // Randomly place money in moneySpace
4 m, G1 a/ ^2 a+ F8 x7 m7 Z    for(int i = 0; i < money; i++){
& z$ ]) c  `9 z! ~  N# S8 ^! c4 R$ J  V* Z2 r3 W2 I! w
      // Choose coordinates
' h4 Q* N5 r/ `9 L$ _( u7 O- W      int x = (int)(Math.random()*(moneySpace.getSizeX()));
+ Y" v; w5 H5 a% G- @      int y = (int)(Math.random()*(moneySpace.getSizeY()));
8 x* G8 Y& Z( h3 o0 _" B
( K1 J' Q4 _7 p5 Q- _' U  f      // Get the value of the object at those coordinates
( D2 R! i, O4 Y  f0 S      int I;7 _' ~2 O# O5 @6 L  f1 O; U
      if(moneySpace.getObjectAt(x,y)!= null){1 g( h" P5 Z( `% O0 Y# x
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();% _& ?2 I0 W) k5 }: |
      }4 T, k& K0 ?- o
      else{
) D. R8 C/ W3 G( c" A1 H        I = 0;
1 `5 u3 k+ {8 l) Q      }
% c* i$ e1 v3 K4 D  O      // Replace the Integer object with another one with the new value- ^' @  r# U* {
      moneySpace.putObjectAt(x,y,new Integer(I + 1));: C$ E& H6 ]6 b5 o( `
    }
1 Y, s- q! O" g0 P. \" R8 o
这里面if(moneySpace.getObjectAt(x,y)!= null){
7 S5 w3 `" U5 r        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();; Q- p8 a, `; I
      }, t1 `6 K4 L* ]0 n2 i0 f
      else{* r; ~) e; I! `- u8 h2 D
        I = 0;
* o) c5 w3 E; |+ ~2 p. n
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?# `, K1 z( u, h* e: ^) [9 i
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-21 01:54 , Processed in 0.021045 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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