设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5315|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
% O. e7 \/ A" @# Mpublic void spreadMoney(int money){
/ |+ T; P. H. [2 ]# c+ x9 D" C    // Randomly place money in moneySpace0 {- U, ^' i( H9 m
    for(int i = 0; i < money; i++){
0 W% k1 ?! ?) y- P1 q+ p( d! L; f5 i# T4 q# p
      // Choose coordinates
! k! l5 M$ p# l/ `* m1 Y& ~& N) b( ^      int x = (int)(Math.random()*(moneySpace.getSizeX()));
& p1 S: k, a7 L) P# _      int y = (int)(Math.random()*(moneySpace.getSizeY()));% l+ ~6 u" Q, D6 t7 v
; Y# \$ c+ D4 a/ m
      // Get the value of the object at those coordinates/ }" P, K* g' x0 w" B4 P
      int I;/ M& q! r$ G' t# v2 U8 t' W5 T' Z7 x7 |
      if(moneySpace.getObjectAt(x,y)!= null){
' n, ^4 e' |8 y        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();, L3 B+ [+ V/ b* R
      }
% }) l  z* N8 m8 B3 m5 U, r. p8 a: @      else{3 D# Q7 c3 _, B0 k3 D' p
        I = 0;, Q) q. c. q) {9 Y/ `3 t+ L3 }) J
      }% ^- `, v. s0 K  ~+ }
      // Replace the Integer object with another one with the new value
2 M8 D: t" O3 {7 X9 s6 Y      moneySpace.putObjectAt(x,y,new Integer(I + 1));
6 m$ Q5 K9 B3 J- b9 }  J1 @    }
# U3 n" H+ `4 S; Z% z+ K
这里面if(moneySpace.getObjectAt(x,y)!= null){5 {. {' a( k7 y& n1 N" J2 o  @$ ?0 A
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
1 ]/ m% z& [" l  ^' |. |% b      }! R6 P! ^% U# R( @# Y7 V
      else{
$ l; [3 G# _" b        I = 0;
3 U8 R9 s7 O" L" I% C, r
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
! u9 d- {. h1 \5 w! M! W$ L8 b5 H初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-14 07:29 , Processed in 0.016569 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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