设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4764|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
! s$ M! |4 O0 L, i7 K4 C- I  zpublic void spreadMoney(int money){
( y4 c) W; ^" E# \9 l    // Randomly place money in moneySpace- u1 O" A3 m5 E" s1 E
    for(int i = 0; i < money; i++){  \& F  b; x; S+ a0 e
% l8 b9 P0 \' j9 y
      // Choose coordinates1 c: ?  E9 i1 D, Z; E, {
      int x = (int)(Math.random()*(moneySpace.getSizeX()));, j9 d$ p0 R8 P4 @. k$ ~0 V
      int y = (int)(Math.random()*(moneySpace.getSizeY()));2 ^1 z7 J% o- b2 j, o3 i  B  ?5 ?1 W* w
$ w; b9 W3 E1 Y' ]1 M* T* O
      // Get the value of the object at those coordinates5 S, ?* g# T) r" V5 B( a7 `3 c
      int I;
9 l: x! a: _, y$ i# W. u+ o. O      if(moneySpace.getObjectAt(x,y)!= null){& z; f, W+ L2 F  W6 J. o1 t( E
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
8 c  S5 H  z. L9 ?- u9 n3 d! w1 r$ A      }
7 a0 e: ^) B' A8 o" G      else{
5 s# R+ c' p" s! l8 I. d9 F/ U        I = 0;( q2 ?9 j; E  I& V$ F0 S
      }2 B. C2 l8 M, D7 O: i7 Y
      // Replace the Integer object with another one with the new value( {9 X; W, H' r7 X. e4 A7 J
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
8 e' \, Y% M6 h: m    }
$ F$ ?. n5 u9 g2 A* S) j
这里面if(moneySpace.getObjectAt(x,y)!= null){2 [# ~' n+ H9 \1 M
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();. A$ v$ x" u0 N' m
      }
& R  }: r' |+ j, z3 n( r" L5 u* Y* o      else{3 c4 B$ C; N: g. _2 i! R/ p
        I = 0;

* Q: W8 i5 N; Y9 g3 s/ w0 `! j是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
, A0 Y: e5 e: w# Q( \- s4 `初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-13 14:15 , Processed in 0.017228 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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