设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4765|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中1 g+ F: ^# a( ?; e
public void spreadMoney(int money){) ~2 c, R# @0 c
    // Randomly place money in moneySpace0 R8 a. z  H4 G6 ]# w
    for(int i = 0; i < money; i++){
; C  }# t; N5 D( J. I1 w2 u9 v; @2 ~( x7 X
      // Choose coordinates
- i" E" Q& v( a8 V% d4 j' {      int x = (int)(Math.random()*(moneySpace.getSizeX()));
+ Y: }' J# u- C$ a      int y = (int)(Math.random()*(moneySpace.getSizeY()));& {1 [/ T$ v+ d- X5 U' t* a; }
7 O4 X. Z. Z: Q0 Q" u" {) ^3 F9 V/ x  \
      // Get the value of the object at those coordinates
' D6 ~' D) w6 e# w6 h3 I      int I;$ [+ ^3 ~# |) x% Z) _
      if(moneySpace.getObjectAt(x,y)!= null){
: {1 ]0 }" ^; W        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();  S; H2 O3 C) f& U; F
      }; g: Z/ q2 s- A4 s# d6 ^+ u5 F5 T6 B. |
      else{' w6 _' f3 c7 r3 G7 U2 W
        I = 0;
3 \" ]9 x# u  @6 l      }, |4 Q- }  ]7 Q# R( Q; W- j
      // Replace the Integer object with another one with the new value
) ~+ e! l# x# C- D( R  ]+ w      moneySpace.putObjectAt(x,y,new Integer(I + 1));! v# `% h7 u7 g  {
    }

2 L$ p! a0 G1 i8 ^这里面if(moneySpace.getObjectAt(x,y)!= null){# f* ^' F% I4 v: H% h  T
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();4 J- z% v% }  e; H  H; v+ Q
      }
3 q' _! i4 g) F" p! D6 _4 K9 m  y      else{
+ g8 B6 i; m: O* P        I = 0;
' J# q0 C( n: r0 O% o# z4 U
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?, k4 C) {# ?+ `, C# `
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-14 01:22 , Processed in 0.016710 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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