设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5273|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
+ N7 c" M1 O( d2 Vpublic void spreadMoney(int money){' c! D4 P9 J$ P% T' g; f& H
    // Randomly place money in moneySpace5 L( F5 p. Q7 X. N: s
    for(int i = 0; i < money; i++){
" z% E' _* Z. B- t' [2 v. W" ?; N) S( U
      // Choose coordinates1 Z. m) z- U& t6 Q7 p0 G
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
9 ~$ N8 M$ `) {      int y = (int)(Math.random()*(moneySpace.getSizeY()));/ o  `0 r" i$ }+ p

7 R& q8 B* A/ R) ]      // Get the value of the object at those coordinates
# m1 U0 k; Q8 F      int I;
" Y; X5 y1 `2 i8 E3 J/ A/ z; V+ e" J      if(moneySpace.getObjectAt(x,y)!= null){" w' L+ n& Z+ g% J4 I% J
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();1 }9 ^  ~5 h3 H! d" b& a0 U' a! n
      }
! _& V# P/ g) V  r/ G: p      else{# E3 j0 P7 x3 K+ V, y( Y+ r4 s
        I = 0;* N; K" z) ^+ _. [8 `2 M
      }
4 i1 p6 h$ ?$ }" ^8 K- T0 y      // Replace the Integer object with another one with the new value
5 D: Y- k2 U+ M% z8 b8 u  {8 L      moneySpace.putObjectAt(x,y,new Integer(I + 1));
8 Y; C# U: n8 t, ~5 v    }

! I) ?- b, n  d" T9 O这里面if(moneySpace.getObjectAt(x,y)!= null){
! [5 I8 X: \; h) e        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();  l9 Z0 }0 T/ l0 G2 B' |3 ^5 f
      }* Z: A3 J) |$ D! B* {0 n2 I
      else{+ d" h9 a! k: W" Y# C# v6 V) g
        I = 0;
1 w( l3 Q7 G4 j' S. ]. X
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
4 B4 l- X; U3 ~( H初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-4 07:52 , Processed in 0.023995 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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