设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5187|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
7 A$ M" m2 U: k: H& g- Rpublic void spreadMoney(int money){2 C0 H6 R6 Y# K) ^3 e& o' ?/ p8 h
    // Randomly place money in moneySpace
) b6 W3 S) o( F2 u9 h: E0 R% h    for(int i = 0; i < money; i++){9 T( a4 e; h+ s/ r
% \$ P2 A& |5 @2 E9 k
      // Choose coordinates" G( q0 ]3 ^0 |* C5 _' d' M
      int x = (int)(Math.random()*(moneySpace.getSizeX()));4 n0 o) P3 x8 N! `% U
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
3 \! N# u/ `% R/ i- R8 q0 H. {2 p! z9 ]: I$ E6 h0 ~
      // Get the value of the object at those coordinates  {/ S! Z8 w; ^* `3 x) v& x4 |
      int I;
$ {: T, i1 i; U! h; [. W7 n% s      if(moneySpace.getObjectAt(x,y)!= null){% D( b( e3 b4 N* O5 B3 w$ o
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();' i* j* j. v$ ^' O2 y0 L: {
      }
$ N/ A* L6 L$ H  B9 C% K: H      else{
; I5 P9 J2 M' H& ^5 j  C        I = 0;' C3 C, b* n* ~- P
      }1 O6 ^" o1 z; }( p3 H
      // Replace the Integer object with another one with the new value
+ H- b+ B- M, o- X+ G      moneySpace.putObjectAt(x,y,new Integer(I + 1));) {) Y1 e$ I2 T; d- A, U3 \3 u7 ?) A( n
    }

* c5 C, X. H: ]这里面if(moneySpace.getObjectAt(x,y)!= null){+ E! W; X: J/ T/ f9 F$ t+ X2 y1 ]
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 {9 M& Q" Q# d* J
      }3 S$ H+ i1 W  a% s1 |
      else{
' O2 a7 G1 v8 p5 ~" N) ?  H( s        I = 0;
  e2 P" f2 p, \. b- k7 d
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?$ s$ R% L5 c: x/ e6 Q8 `
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-20 03:12 , Processed in 0.015229 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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