设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4540|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中3 V1 G/ M* l7 }8 O
public void spreadMoney(int money){9 F/ e. a4 R1 @' ]
    // Randomly place money in moneySpace: k, C: ]  o3 |! G5 p
    for(int i = 0; i < money; i++){" w5 Z  ]9 I( \; Z  h5 k' S

; s+ a( l* L: \      // Choose coordinates
$ L; H& b5 l3 l8 F7 Y      int x = (int)(Math.random()*(moneySpace.getSizeX()));) N, `" J7 q5 ?  |3 X% n
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
6 K9 c9 K2 g3 }: {& _9 u- g. N' n1 {6 C" ^! i% T0 D6 C$ O8 B
      // Get the value of the object at those coordinates
. R0 }9 C, c* r6 H1 p      int I;
( ^" T' n. N6 I0 U9 K! ?" g1 w; N      if(moneySpace.getObjectAt(x,y)!= null){
' U0 x) Z2 C6 H+ N        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
  r2 ?8 f0 T' k8 z3 T2 C      }
$ M" r0 v2 O! c4 @# U      else{, R( y% X: |5 x3 d/ K; R
        I = 0;
, x3 F. v5 R2 s2 h      }" n* I) V. `5 @* m$ p- U* \
      // Replace the Integer object with another one with the new value! t; V1 O8 r9 p3 x7 L* O. P* `
      moneySpace.putObjectAt(x,y,new Integer(I + 1));1 g+ s  [7 z: O, \/ {$ i9 ]
    }

: u: r$ R- `, ]. h! n  X6 U) M这里面if(moneySpace.getObjectAt(x,y)!= null){
+ [2 s- O. e1 [        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
$ k  |- f9 R  W      }
6 v$ L. ~4 V/ c5 ?* E* e, L      else{
8 m" C- @* l5 }: w/ N        I = 0;

  c' j2 E' [! }  v% f% G是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?0 \3 U8 }! q. P4 p/ H
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-2 22:26 , Processed in 0.013426 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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