设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5288|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中$ }. Y+ V- t) `/ N$ C) t. m
public void spreadMoney(int money){. a7 N7 q( [( h3 p4 h/ |
    // Randomly place money in moneySpace" s" l! C9 y1 X
    for(int i = 0; i < money; i++){9 c9 c; \9 u8 L6 M0 v5 ^  [2 I
  L+ |4 t  v! X1 c8 S$ W
      // Choose coordinates- A2 w. T* Q; S
      int x = (int)(Math.random()*(moneySpace.getSizeX()));2 m  ]( n) c, [# F0 G
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
9 O8 ]( `% m$ A3 y
  v5 _, v7 u" H( M! i      // Get the value of the object at those coordinates
6 h/ A5 _; s  a8 l, p2 C. W      int I;8 h" I0 H/ ]; g* f
      if(moneySpace.getObjectAt(x,y)!= null){
/ }, q5 A3 ]( f* s        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();. l9 x4 J8 O' I! d5 O
      }
, b/ a7 O( J) k+ v4 M      else{. Y# i+ ~$ a, O
        I = 0;9 A% V! K$ W/ A$ h. L
      }! L: S" p% ^. R% N3 R& e: J
      // Replace the Integer object with another one with the new value% `7 n9 n2 r) ~3 d! q: E
      moneySpace.putObjectAt(x,y,new Integer(I + 1));6 J, j* \7 `4 N. n5 O% K+ g
    }
7 E' s( O. p6 _2 c
这里面if(moneySpace.getObjectAt(x,y)!= null){% s" c; _6 Z2 a6 m9 U
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();% z$ V* [! b4 i0 F; n5 i
      }: z1 @/ s* ?: M& {+ i
      else{4 n& x9 G/ e* v; e7 H3 W  w
        I = 0;
/ p& E9 {# E% Y. q+ L. e
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
9 ^# j% ?, {! n: V- G9 Q6 Z$ ?  b初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-7 05:16 , Processed in 0.022227 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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