设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5430|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
! o2 D$ W: H) opublic void spreadMoney(int money){
( s1 Q* p0 F3 f7 O5 {% O    // Randomly place money in moneySpace
, U. L; j  {3 N0 Q    for(int i = 0; i < money; i++){, j' E; S6 D' T+ W/ k  `
4 x% ^5 q) o$ o0 Q6 \' [9 \
      // Choose coordinates9 n) N; o) V7 w7 i* d
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
! ]1 X0 W% A% ~- o" z: y1 i  J      int y = (int)(Math.random()*(moneySpace.getSizeY()));3 v* o* p& j& o/ y

$ t7 p% y2 D7 L( h/ \: a      // Get the value of the object at those coordinates2 i- C' N1 e* y$ O) U6 G' }
      int I;  r# R+ N7 ^9 Y& [0 [
      if(moneySpace.getObjectAt(x,y)!= null){
6 a& }7 J; X+ b8 C7 X        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();9 q7 ?# J4 d9 p: A2 i8 {
      }
; l- ?9 @& f8 \" P4 D      else{! X6 ^. K5 U' W8 i
        I = 0;% ~6 ]- }: b# W: a1 U6 T
      }1 p: _2 A# ^3 x# e9 o5 ^  r
      // Replace the Integer object with another one with the new value3 k2 ]. i  O& h' b7 J$ e2 D9 f
      moneySpace.putObjectAt(x,y,new Integer(I + 1));2 o7 Z  Q" {2 w' {0 m. b2 c
    }

+ J4 D9 ]5 B( v7 j2 y这里面if(moneySpace.getObjectAt(x,y)!= null){; I" d) `9 N6 [. K) g3 ?' H
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();4 f$ [: J# @& m4 q
      }% G- {$ x4 J) n7 V
      else{
  N5 ~; m9 @7 R0 [* i        I = 0;
* ]8 n3 t8 }* }$ {( |
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?& D* m( w8 p2 |: F4 }8 c) k) Z2 s
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-18 12:09 , Processed in 0.016197 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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