设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4175|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
+ e& h! K: E4 \6 ]$ y& bpublic void spreadMoney(int money){& H7 i0 N" w4 ]
    // Randomly place money in moneySpace
" U% \  Q% O6 J6 k+ ~% S    for(int i = 0; i < money; i++){  z* s/ K% S9 n$ L
* h8 @7 S2 Q/ e4 V' G0 t! j
      // Choose coordinates
/ l# c& z4 }/ a- E3 g      int x = (int)(Math.random()*(moneySpace.getSizeX()));/ D. S) W. i$ z2 C' A3 u
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
: H8 d0 k/ f2 b3 H! s% h5 G  u- T# u7 _
      // Get the value of the object at those coordinates
, Z; R3 Z$ B. V% A/ ?* c      int I;5 R2 [3 H9 [6 y- r* T+ K$ I
      if(moneySpace.getObjectAt(x,y)!= null){
) e* M3 T9 d# p        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
; v+ s# \, k% T) T" X7 W- O      }
- T0 }8 @* T" n/ |      else{1 r4 D& w3 N) m6 `
        I = 0;
# k3 v3 @7 `6 i9 \      }8 G- y1 F2 n& R$ m
      // Replace the Integer object with another one with the new value
" l! R& d# B3 _/ Y, q  N  p/ u      moneySpace.putObjectAt(x,y,new Integer(I + 1));
4 {3 t4 ]7 L2 K4 g9 V8 ?    }
- H. _6 [! B  }: b
这里面if(moneySpace.getObjectAt(x,y)!= null){' ~9 S7 B3 K; H3 K: e
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
- g9 g$ r& g' T# p0 d; z      }
* V. r' H% Z8 I" }      else{- l+ j  {0 H/ T1 N' e
        I = 0;
" E) H) `% U) ]# f
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?: R* f; ]5 a$ t( M" \6 y+ m
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-3 12:08 , Processed in 0.015163 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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