设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5210|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中4 N* f) ^2 O7 ^7 i6 ^0 B2 a
public void spreadMoney(int money){) p) [7 h' {# L0 ^
    // Randomly place money in moneySpace- w* b: B7 u/ {/ w2 P2 N  R
    for(int i = 0; i < money; i++){
. x* f9 w( ?  g7 Z9 M2 t% T( }( o
+ I  O+ V1 \, D      // Choose coordinates- s" @! G; d, q% ?9 T, N) q
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
1 O: h) ~1 r, `0 \      int y = (int)(Math.random()*(moneySpace.getSizeY()));
; O9 D( Z- @# x5 Q2 [
! y2 m. J# M4 Q+ F9 _; i4 R      // Get the value of the object at those coordinates
/ B1 P  A% Q  q. T6 T( l% |      int I;% ?* }* z! p4 G, X/ c
      if(moneySpace.getObjectAt(x,y)!= null){
+ l, O: q+ q) J* ^! b3 X3 s        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();1 j/ L3 n  N5 a% g  m' m9 S
      }
5 l; h2 U; ~) n# W      else{
( _3 C8 u' c5 [% ]! ^2 B( ^) p( h        I = 0;% w/ |% f* D9 e1 _! `
      }" S9 s; Z  }" Y/ H
      // Replace the Integer object with another one with the new value
* Z0 n8 ]% ~/ G  n, B8 {      moneySpace.putObjectAt(x,y,new Integer(I + 1));
: X/ S: h/ k4 K/ e0 i( P2 F7 v3 n. m    }
, B4 `9 O$ `# L3 x$ w8 b, E
这里面if(moneySpace.getObjectAt(x,y)!= null){
  I  U9 p* k2 Y$ f' `        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();( n' z+ Q/ e7 F( S) H
      }
& ^$ @1 i9 Q7 I) |- i$ ]% L      else{9 C: D3 N4 s' `, O+ Q! p
        I = 0;
# |; v6 \) n$ ]$ S4 \% {
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?; r: n, m5 {# y( ~( G1 E
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-23 18:33 , Processed in 0.015645 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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