设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4579|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
0 F: ?9 J4 d+ s9 gpublic void spreadMoney(int money){: X/ d1 }* x7 j0 ^
    // Randomly place money in moneySpace* M" b+ n8 F  U1 N8 _
    for(int i = 0; i < money; i++){
4 m" b' E4 r) y& b6 R9 `; }# T0 ~+ F! \6 {4 Q) O" M; \& t* e
      // Choose coordinates1 l% H3 w/ `7 c1 ]6 ?4 F+ K
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
% V* M. S2 a' b  x( l; F      int y = (int)(Math.random()*(moneySpace.getSizeY()));
- {1 F+ L' Q( J3 f" `) \' R
1 u/ S; _5 }! V7 ~" o0 o3 [      // Get the value of the object at those coordinates( a2 M9 U. f% T. w* ~- ]/ `
      int I;' b0 G, b+ Y! l; Y0 x+ r4 l/ R
      if(moneySpace.getObjectAt(x,y)!= null){
8 f0 l9 A$ p3 r+ T5 @        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();" Y$ g5 R, p. ?# F6 {6 i
      }
" e  C  F1 M/ O& U3 l      else{8 y2 L: |5 R4 O8 \" H- g
        I = 0;. z* D$ c- }/ c2 n. E! G( h0 i* Z0 Z
      }  \/ p6 h; m( K  m! i0 E
      // Replace the Integer object with another one with the new value2 q! J+ k2 l" F; [
      moneySpace.putObjectAt(x,y,new Integer(I + 1));9 Z* t( b8 r. F9 _
    }
7 U" Q  O. W, x0 t1 w, d* {
这里面if(moneySpace.getObjectAt(x,y)!= null){/ K& J1 e- V2 C' ~9 T# W
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();4 c& R. |4 |5 M# ]( n
      }0 r6 L* Y% B/ U. L8 w; G
      else{( |" ?4 Z3 F9 A4 Y; o. v
        I = 0;

  t7 w1 G6 m/ u; m% T  \3 U  d. m# M是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?! j5 T" x% m. L* P; o
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-19 20:04 , Processed in 0.017220 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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