设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4638|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中  f  T) U0 B7 P* y
public void spreadMoney(int money){
, R: w4 Q& _' t% M, J    // Randomly place money in moneySpace
. ]" _1 F1 i3 q2 }/ L3 x    for(int i = 0; i < money; i++){; w; I3 `4 m8 q* _) W0 X  z. g. x+ [5 C
& z9 }2 T. U3 ~: m$ |
      // Choose coordinates+ e$ O' P3 k( B" _
      int x = (int)(Math.random()*(moneySpace.getSizeX()));9 |% o: R7 Z6 p' w. j9 p7 ~; G1 w
      int y = (int)(Math.random()*(moneySpace.getSizeY()));' [0 K' y: v4 g) |5 _
' X3 S; y& i6 \1 S% u. {* W
      // Get the value of the object at those coordinates
+ _( }" B6 G! p" u. T      int I;; B, [: U7 P% Q) j2 V8 X
      if(moneySpace.getObjectAt(x,y)!= null){
( g* a6 ?) E6 H& ~# v        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
4 k( x2 I# p; ], ]# |% {      }
0 U2 W' W& w; f' d4 ~- V      else{4 }6 e; w' J' e) h( O6 q7 `
        I = 0;, t# W" @4 H( S) E
      }$ x" j8 Q* P! E6 o) e% B
      // Replace the Integer object with another one with the new value
4 C. u: C. G* u      moneySpace.putObjectAt(x,y,new Integer(I + 1));6 v) s* U2 I( D7 L0 D. e% _. O
    }
5 ?  G4 E* @+ D  F, p7 q
这里面if(moneySpace.getObjectAt(x,y)!= null){
; y( Q$ E/ U' p1 g. \        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();9 ~  L7 G+ X/ P- ^$ p
      }1 W& S1 B+ i: O" G3 U/ j) F; \
      else{
6 t) d: z) C5 ^( e5 `        I = 0;
0 K- V) D! D8 f! f" O
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
4 L7 K5 g, n7 [' v* H5 u) |0 N初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-5 08:38 , Processed in 0.013299 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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