设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4502|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
3 k, d) g. Q3 ]1 Wpublic void spreadMoney(int money){
! A3 S' M2 ^- @3 l9 g5 w* G    // Randomly place money in moneySpace7 [4 s) s' {, Q+ Q% k' {  V& f
    for(int i = 0; i < money; i++){
1 @; j, x5 [2 N7 Q  Q1 u  N. {! O/ d) k: ^3 `" _
      // Choose coordinates
) E% ~  I" r+ d$ ~: o  h, ?; ?      int x = (int)(Math.random()*(moneySpace.getSizeX()));& K3 @( i* H$ @5 z- j
      int y = (int)(Math.random()*(moneySpace.getSizeY()));# }) S# p( \$ X" V/ z$ x
8 P+ L0 }4 v0 A" U
      // Get the value of the object at those coordinates" D( a- p& L9 \2 q9 r5 g
      int I;+ X8 {, G) O" m# M
      if(moneySpace.getObjectAt(x,y)!= null){6 w4 f' g0 u) y
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
1 c2 b+ y0 S2 l: s! ?& w      }
" R1 a& @* m: o3 |# b      else{2 c3 T! Y8 ?2 v- r
        I = 0;
- D$ q9 k" z: G! y) d      }1 P5 u6 S. J, {( S
      // Replace the Integer object with another one with the new value
9 @; p2 P. E# j+ w& V      moneySpace.putObjectAt(x,y,new Integer(I + 1));
1 j' |3 L9 I8 o& T' w+ h    }
6 L5 t. N9 z, k4 `
这里面if(moneySpace.getObjectAt(x,y)!= null){% Y' v: ?; a$ S
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
, `' ~# [2 @# j. \/ ]2 M      }* H2 L4 p2 }; i9 L* _- q9 B. T1 ]
      else{) [! `5 A  ]; @. R# h5 Q. _. A% P
        I = 0;
" K+ C+ p! H/ l3 Q  V- Q" M
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
- V: m- _# q2 Z' E初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-20 21:31 , Processed in 0.014169 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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