设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5038|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
! T' w  b7 k. f( E9 Epublic void spreadMoney(int money){
* J/ `" O6 O: j4 @% c, k    // Randomly place money in moneySpace
: A1 q3 D! y7 O! Z  r$ q) d    for(int i = 0; i < money; i++){
2 C) f1 a4 k. @& A
; d- D) v( L5 e& d6 V      // Choose coordinates
! |' I  v* S& U* }; V  Y      int x = (int)(Math.random()*(moneySpace.getSizeX()));3 S$ ~( x1 B, ]$ d1 D. b- l
      int y = (int)(Math.random()*(moneySpace.getSizeY()));9 C: K* X# o( _: @

  p; o. d1 @' d; b( r+ U      // Get the value of the object at those coordinates
' B7 x# d* \6 Z9 _: N" J      int I;
  ?! a- O' i* ^/ U5 O$ Z- \5 F      if(moneySpace.getObjectAt(x,y)!= null){
, ?" O& x% |: O" W, F- |8 ^( L        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
* ]4 E. h& X/ \9 w" |. E      }
6 [0 Y& L# S) R+ o      else{
7 x5 }0 f+ h. s; N        I = 0;
; U0 v8 o4 P  \" M" V/ r0 e      }/ q$ d4 _4 i/ s( w& ?7 ]. p. ?
      // Replace the Integer object with another one with the new value
0 d- J5 {) C$ @, F9 n      moneySpace.putObjectAt(x,y,new Integer(I + 1));; w3 X* S5 n" B6 h- V, Z
    }
9 {0 D8 ~( t+ b" e5 b# O0 J
这里面if(moneySpace.getObjectAt(x,y)!= null){
% k  [3 ~8 m5 a! c! t4 a5 ?( \        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
' V: m. u' [' ?2 o5 Q+ _% H3 p$ j      }# M' b* E& B1 [0 y( M+ V. ?
      else{; m! u9 f4 n' b6 h+ N+ h; G
        I = 0;

7 ?0 V, x4 w' ^; P0 M$ N2 g( w/ H8 Q是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?" ^1 t& n0 R* a8 [1 M8 _! x
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-5 01:23 , Processed in 0.015062 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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