设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4831|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
1 ]- f& ?, m# c+ N* ~, A) rpublic void spreadMoney(int money){) n" s# d: Q2 r
    // Randomly place money in moneySpace) u! @% W* W9 \
    for(int i = 0; i < money; i++){
4 ~0 a" k7 U/ f0 H' P* }+ s# @7 q, q5 n& c% Z, u  @- L
      // Choose coordinates& g9 S( G, }7 |* O1 y
      int x = (int)(Math.random()*(moneySpace.getSizeX()));6 g7 R/ T9 J* {
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
# g% K0 c; |2 I$ x  G2 y+ V4 Z; K6 n7 D" w. @
      // Get the value of the object at those coordinates
* @; P8 [5 ]8 G. o# @& z      int I;- v( g# W& @- V( O9 R+ {' z# w
      if(moneySpace.getObjectAt(x,y)!= null){, u4 Z3 m- X6 K- P) E0 t+ L
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();* U6 K/ }  Z4 _. @5 f
      }1 ^' u7 `0 {( l! j# Y3 W9 d, d9 o
      else{
: e8 V/ Q: Q$ s2 V$ r        I = 0;: N1 A9 G/ M3 w1 ]. M) ]
      }
$ U! I# }, d. g, s      // Replace the Integer object with another one with the new value
% E. X5 T" d, W5 l- Z, S& k+ X      moneySpace.putObjectAt(x,y,new Integer(I + 1));8 b# O% n, b, e" n: _+ U6 V" Y7 f
    }
1 f& _2 o, e; t6 {
这里面if(moneySpace.getObjectAt(x,y)!= null){: d% ]+ R4 M2 X& Y6 Z8 M
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();0 f. j. s, q# g8 q1 t& o: p
      }3 `/ O% q4 `$ f7 |( e
      else{
- t( U: o' L3 B1 d% B        I = 0;

4 ^* P$ F( J+ t3 ~! t是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
  b8 j2 p8 |5 K7 |- n" ]+ R初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-3 04:15 , Processed in 0.018807 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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