设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3860|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
5 ^6 @# l. @: e: xpublic void spreadMoney(int money){
7 v  |# X' j  c" C+ i  {    // Randomly place money in moneySpace$ e' P$ ]5 C/ M0 v6 j- f4 [! b0 q' y& E
    for(int i = 0; i < money; i++){# `# z  F) @# [3 z" A9 E" a
$ K. X' n, b9 T1 T
      // Choose coordinates
; Y( V& E& N7 ^  t( t      int x = (int)(Math.random()*(moneySpace.getSizeX()));
% a+ P+ L* @2 a; Z      int y = (int)(Math.random()*(moneySpace.getSizeY()));+ j9 j. {: s& C  N0 G4 s5 z

; K# e: f* e) H: I( l2 _" p      // Get the value of the object at those coordinates
2 t3 w0 T4 {( T4 c% X      int I;
+ X! V5 N$ r: ^      if(moneySpace.getObjectAt(x,y)!= null){
- B; |2 v( `0 Y# L        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
% c% L9 T1 ?+ K6 j5 [8 @      }
4 J$ Y& m1 G: R5 P1 |      else{
& b7 H' [( E; [3 n8 K) n        I = 0;, X/ ~  Y4 V1 a0 D. j' I9 `
      }
' c( u# i  d# u# K1 p5 Q      // Replace the Integer object with another one with the new value0 M3 F6 m2 `. H
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
) X/ ]/ U2 y# R% C& {$ K5 e- A    }

- U4 W7 Z! r9 {9 ?. \# p% k% Z/ N这里面if(moneySpace.getObjectAt(x,y)!= null){: ^9 x1 h& Y4 K5 h# Y$ C
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();4 b2 u# I; m. B6 l' S$ W9 ]& H* E
      }
3 R6 ]9 ?3 `( ]* I0 d( Z8 k      else{
0 f5 o* W$ n5 c        I = 0;
( B) h3 `6 ~; p/ l! ~! l
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?  Z2 A* I. I$ v
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-3 06:38 , Processed in 0.014826 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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