设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4397|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
% J3 U  p  a9 w4 `public void spreadMoney(int money){
  `: _( V4 P! S" n3 `5 _    // Randomly place money in moneySpace: l  e7 B8 W  \5 s
    for(int i = 0; i < money; i++){
4 Q- x2 _! G9 O6 w5 W2 a3 k+ b& |& D+ P( B' `; t% n5 @4 @2 p
      // Choose coordinates
3 |6 [8 B# R, }! M- W* M; q8 Y      int x = (int)(Math.random()*(moneySpace.getSizeX()));" a4 e; s6 s. v: ~% S
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
( ^+ U  O5 x# z2 n1 k: ~. a$ a* L
      // Get the value of the object at those coordinates
1 R# B+ a. t7 |& N- g      int I;
5 S1 S3 B7 D2 r% x. f5 |" z$ @      if(moneySpace.getObjectAt(x,y)!= null){
0 s! u8 p1 [. s; b1 y        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
( d2 G5 a" J/ j8 D" ]      }( w; G  J3 H) S. [2 }. M
      else{
/ J, W1 ?; j  v3 {1 ?( N2 N' q1 y: U4 [  Q        I = 0;) h4 y" K' Y1 U
      }, o* G0 s3 E/ R( d, ^# Y
      // Replace the Integer object with another one with the new value6 A6 n$ a# X' j* J: J
      moneySpace.putObjectAt(x,y,new Integer(I + 1));/ X, f/ H. X/ U% w7 g
    }

* U* k/ s+ R' a1 j$ [这里面if(moneySpace.getObjectAt(x,y)!= null){3 e5 p" Z9 G" x2 V
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
% Z# m9 G. `- A5 g4 T" t3 e      }
8 Q; _2 Y, L% L- o" [6 `1 W' x2 a      else{
) I5 x; ~! L$ Q6 y6 V* w# f. o        I = 0;

; w; ?2 D! f% Y' g) ~是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
$ m7 K9 g: z+ K7 @# @初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-18 19:10 , Processed in 0.018730 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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