设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4503|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
% k7 w4 i: m2 w9 U1 G. g, S1 _5 Fpublic void spreadMoney(int money){
+ w* m7 h# k* v$ d    // Randomly place money in moneySpace
" s& w3 j7 u' F9 `  j$ g0 K+ \    for(int i = 0; i < money; i++){, J+ m! {2 s1 D

/ G8 e( U4 `1 e9 U; i  I, z! Y      // Choose coordinates
: S; _+ R6 x& q" P      int x = (int)(Math.random()*(moneySpace.getSizeX()));
- E, }$ }/ \* v$ [/ h      int y = (int)(Math.random()*(moneySpace.getSizeY()));
( B# X, l. q9 w! |8 }# z6 p4 D2 D2 h& M3 C6 d7 k* ^
      // Get the value of the object at those coordinates
, n: I# [  \: ]& X* q      int I;
/ f1 N9 l5 V5 {      if(moneySpace.getObjectAt(x,y)!= null){1 _  {& b; i6 }* S& K' W* L6 V
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();9 a  G. f5 X: n6 P1 M9 r, O# ^& o
      }
" r8 b% I8 g( \% y" ?. s: x2 @      else{
# \3 Q+ a2 t- O1 q        I = 0;
) R* U& C4 ~: M      }
" z# F3 V) s6 V0 Z      // Replace the Integer object with another one with the new value
1 H5 }$ }& j+ e; @      moneySpace.putObjectAt(x,y,new Integer(I + 1));: Q$ ^9 W% I$ B* Z
    }

, d) H! i/ p  {5 N, V, V: v这里面if(moneySpace.getObjectAt(x,y)!= null){. W3 o/ s; J; @: A$ S7 Y
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
9 V6 p3 e  z! }5 ^9 k" J      }% c! h9 P6 Y) n# M: Z8 {) K- P
      else{* w1 q' N/ D# J& y) R+ `
        I = 0;

- h+ a8 g% `. v; A是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?- D, M- E" ?4 P* g8 h
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-21 05:31 , Processed in 0.015079 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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