设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5489|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
7 T! ?7 K( B5 xpublic void spreadMoney(int money){
5 x: P! Q7 Y1 u# _4 I1 H/ f    // Randomly place money in moneySpace$ Y( {! C+ Q7 h# m$ m% s* ]
    for(int i = 0; i < money; i++){5 Z6 T" I) s5 {" K8 w# j! @
2 W1 }; m" g3 z8 k; U
      // Choose coordinates7 u; U+ C( v' `
      int x = (int)(Math.random()*(moneySpace.getSizeX()));# o6 e7 Q" Z1 C, e4 B8 O
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
* }# `$ f% z. i5 S+ \  `/ L& i( ]' [# }
      // Get the value of the object at those coordinates
0 W/ V" u. B0 I. z      int I;: ]. m/ Y: I8 Z. [
      if(moneySpace.getObjectAt(x,y)!= null){( u; F% i( d: P7 h! h
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
9 m9 o* T8 x9 _% d; M- z      }
8 l- t) p8 W' j% z/ O      else{, @0 N2 Y5 @& l' c. C
        I = 0;) x7 U* k( U) ?) Z0 a& @
      }
5 h2 b5 r3 }( l8 t: t8 b      // Replace the Integer object with another one with the new value
7 i& Y1 w2 A- [- S) Q5 U9 F8 {  v/ G      moneySpace.putObjectAt(x,y,new Integer(I + 1));
8 q2 `' M1 F2 u2 F    }
0 ?) A' w8 L5 m
这里面if(moneySpace.getObjectAt(x,y)!= null){
0 e; E$ k; e- `' y" t! V        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
% w8 P4 v8 k" u; v( J* b% I3 ^      }' G- e7 t+ g' ]* S3 m& K% e
      else{
1 ]3 [7 `8 [; d  j0 o        I = 0;
- t5 R& k% `' r0 b/ [* X7 i
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
6 w" I# @* ^4 c) H: _' B8 [初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-25 11:10 , Processed in 0.016418 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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