设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5056|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中2 H' a1 H3 K8 T
public void spreadMoney(int money){
  H1 f' z7 D! j- X: [4 z    // Randomly place money in moneySpace
6 c) D+ s4 U# S% e2 e9 k    for(int i = 0; i < money; i++){  R- M! z: K+ Q; {
" i" c. ]/ y0 a9 b( l" b
      // Choose coordinates
8 P. P$ a) U) t      int x = (int)(Math.random()*(moneySpace.getSizeX()));
4 f7 D5 p* @0 m% X( E; u/ M. V& r      int y = (int)(Math.random()*(moneySpace.getSizeY()));
9 [! `3 p5 ~; T; W3 M9 ?8 k$ S2 ^7 X3 [$ Y- U: _5 H
      // Get the value of the object at those coordinates
( X4 R7 p1 g" ~" N. f' I      int I;
7 D+ J2 _/ Q- o  ]      if(moneySpace.getObjectAt(x,y)!= null){
% b& D6 ]. b% ?        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
0 C8 u7 d1 E% @  ]: y      }9 R8 a9 o& D/ \' {
      else{
( h+ |- R, L' `" O3 ^& T0 x% L" }        I = 0;( ]" r$ d+ i; T) N
      }
3 p! Y) y2 f; x7 S. }4 X      // Replace the Integer object with another one with the new value
5 G: F- @% c' {% m      moneySpace.putObjectAt(x,y,new Integer(I + 1));3 }" |4 q# l4 Z, G% h5 b2 T( N6 X- s5 j
    }

  k) r) t, `1 o: t3 l: p这里面if(moneySpace.getObjectAt(x,y)!= null){
4 o2 {4 x. y- c6 J' e        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
. g( {1 S; @: C, [  J      }
% H+ _- Z: t' {      else{
( H; `8 T% d) \        I = 0;

3 i: w1 F  g9 \是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
/ u  G1 G% ?" A0 G' H1 a初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-11 21:07 , Processed in 0.015755 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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