设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4258|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
, m  H' z1 B  \$ O1 t1 \% {public void spreadMoney(int money){9 A! `  y, I. m3 B4 D# g
    // Randomly place money in moneySpace
2 s  u- _) W" j! _# K; X( |    for(int i = 0; i < money; i++){
9 [6 r/ c. r8 b& \9 B
" S7 K# ~1 j3 a+ z  K$ Y      // Choose coordinates5 `% d% l3 D* z( `( c
      int x = (int)(Math.random()*(moneySpace.getSizeX()));% B' g' d; L9 i2 r
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
/ M; o7 Y9 u9 T& Z# c2 r8 |- f% l/ M% _5 i+ |7 T: o2 t
      // Get the value of the object at those coordinates
/ N/ {& S" ?" l0 W      int I;* R! x7 j0 e0 M$ o: H  r/ r# P+ b& v
      if(moneySpace.getObjectAt(x,y)!= null){
' v, a- U' U2 U8 F+ C  L/ D        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();- C  N/ q! M3 b" [8 q3 `, u
      }
6 `! R- C9 d; k+ U2 K      else{
% I. p: W) H8 `$ P& h        I = 0;
1 d3 Z0 Y  u3 U      }1 L: z8 t, k/ o) ?
      // Replace the Integer object with another one with the new value' u; E8 L5 l5 }- D- V  y
      moneySpace.putObjectAt(x,y,new Integer(I + 1));. q' _4 \, `& {# J! `$ k- z( k& O8 f( t
    }
5 r8 U" z; U% m
这里面if(moneySpace.getObjectAt(x,y)!= null){* g* n6 i( l: `5 p5 |* h/ q
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();/ [0 |& B* P  F% L* _3 h8 F( s* V3 t
      }
/ f; v$ l' H8 ^, p      else{7 T5 U) ^  X; u; }
        I = 0;

" f7 P$ m. Z% O' T4 n* }是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
1 ?8 D0 v6 ~7 b# _+ n初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-27 03:12 , Processed in 0.018913 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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