设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4124|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
7 c# p4 X7 |* B+ r; |$ f9 jpublic void spreadMoney(int money){
* \% V) Z  h3 z8 I$ B. ^: W" L    // Randomly place money in moneySpace
! {: s% T/ I6 ^9 O5 ?# B    for(int i = 0; i < money; i++){
; t9 Q) W% x" ?. |: k4 }1 ?  O- S* A- H4 x) Z
      // Choose coordinates! l6 f0 K4 H: Y% ]; u
      int x = (int)(Math.random()*(moneySpace.getSizeX()));. `/ }6 p- o/ ]. ~" m
      int y = (int)(Math.random()*(moneySpace.getSizeY()));# T  b* _' F- T, E1 ]$ G. K
) H' Q* p* ]1 ~, O/ e
      // Get the value of the object at those coordinates& y) X% f( K2 D+ ?# O8 @( Y
      int I;
/ h) |, ?+ q6 ~  |! R      if(moneySpace.getObjectAt(x,y)!= null){
* {  {+ c+ b4 C) s: c; x        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
0 V3 |( Q" `0 O4 Z% s      }( }$ P( g% P# P, `0 _! d
      else{. \; Z: s4 q/ b/ o
        I = 0;
% b" Q; Z7 n/ e5 E" B$ ]1 A3 K% Q      }
# E9 u1 N! @6 t* j( N' n      // Replace the Integer object with another one with the new value6 I+ ^. p/ K8 e8 u
      moneySpace.putObjectAt(x,y,new Integer(I + 1));9 z+ F* G6 R3 J; c$ \1 a2 S
    }
) F! x) A) t( \. [: c5 Y: J
这里面if(moneySpace.getObjectAt(x,y)!= null){. `; B; p5 Z3 a
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
& m& u0 g, a. t6 o* F7 @# V( I, p      }; ~9 O  I& x' S! ^- A
      else{
9 r8 j  X( U- q" I5 C5 ~, q        I = 0;
0 h" _: A" {( h4 [/ E
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?, D) n/ j0 A2 e5 _9 Q  s
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-18 21:25 , Processed in 0.014339 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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