设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3841|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中: E/ H( q9 z$ W# O3 L/ I! J
public void spreadMoney(int money){* S" y# ?" X6 }2 j
    // Randomly place money in moneySpace
9 q8 K* j% j) j9 n    for(int i = 0; i < money; i++){3 v" F. u  |* ~$ }7 w+ G
. O  y! b% U0 W  g4 b1 d: v
      // Choose coordinates
: [, e2 z+ o1 R) G" Z* s- K% T      int x = (int)(Math.random()*(moneySpace.getSizeX()));
/ J+ g9 }7 b3 \* c      int y = (int)(Math.random()*(moneySpace.getSizeY()));1 @- L1 Q& M& R( a9 a0 Z; o; l
: s3 ]7 N5 Z: W* m6 L: s
      // Get the value of the object at those coordinates
8 H1 u5 Y9 o! J1 Z2 b      int I;$ S. `! v8 b9 }4 M$ I8 w
      if(moneySpace.getObjectAt(x,y)!= null){
6 S9 {1 R$ a4 t; ~) O        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
6 @/ X' ?, p$ v9 e7 g% m4 K  J) V) r      }  j6 y# I9 C7 @4 X4 }: h+ H
      else{
0 Y, S" R/ Q) c/ ~4 }3 t0 P        I = 0;
9 I. f; w9 Q$ ?$ Z7 J: B/ H      }: H0 B: K6 P5 t* @6 R
      // Replace the Integer object with another one with the new value
  ?8 X3 v5 f- N  W/ l6 }      moneySpace.putObjectAt(x,y,new Integer(I + 1));
% y4 Z* l; j/ G' `* ^6 [9 U    }

: L6 O- w$ W, a这里面if(moneySpace.getObjectAt(x,y)!= null){9 `" @' J6 Y" o7 F8 y2 Y3 c# R
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();- v& F- ?3 Z# F; T: B
      }
) v/ O# v* G& U; ^0 ?; U" O6 p      else{! H4 p: v8 R) L( f
        I = 0;
7 B- X! U0 T- Q5 L) e* }
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?% k: N4 c" f8 o- G
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-6-26 16:54 , Processed in 0.016804 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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