设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5017|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中* l4 u5 y, P- ?  @  U4 |
public void spreadMoney(int money){3 V9 M' Q/ H! H. a' u! h
    // Randomly place money in moneySpace$ W6 f2 v" P  I5 z# p. q% a1 t
    for(int i = 0; i < money; i++){
4 N, O0 C) Z" Z5 U6 \' A- ?" Y
8 F* p2 ~7 M+ I6 I0 }      // Choose coordinates
7 z2 N9 z8 u3 i: g1 O      int x = (int)(Math.random()*(moneySpace.getSizeX()));
" L) ~8 P. J1 g& s, {) x. {      int y = (int)(Math.random()*(moneySpace.getSizeY()));2 y+ w% w+ ]2 [5 y) v

- g9 H8 A( p. i- E      // Get the value of the object at those coordinates
# O, F$ x8 |$ F  ^3 S- n      int I;4 Q* H: Q1 N* ?
      if(moneySpace.getObjectAt(x,y)!= null){
! j2 A, G5 a$ h; ]# Z8 p) i        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
% ^) {% c/ ?, X5 ]+ A( R      }, g. _5 ]: P5 a( N( g% ~! @
      else{
  i" G1 J* B3 D, ~  m/ F3 ^, H, p        I = 0;
9 C. _; o! H+ X' y3 E! t      }
. P6 |; @# p2 U7 j5 o$ |      // Replace the Integer object with another one with the new value, j' P8 E: E8 w" c! |: O
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
2 [/ P& ~+ b9 ^* D3 l  ~. E. h9 q4 i    }

+ E. T& \% ?8 a) a, e, J这里面if(moneySpace.getObjectAt(x,y)!= null){
: ?4 l: C; z6 x1 _. A  z1 S6 ?        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
, n3 V1 q$ J3 s8 f, P      }
( r6 t1 U1 W/ J$ h( g. t) s8 [      else{
1 R, c( ~6 Z% T! k" w" |2 A" D        I = 0;
8 x5 W( F, f" [" K
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?4 y. i2 U3 c9 v0 P" k* K0 O. Y
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-21 22:14 , Processed in 0.017338 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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