设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5103|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中3 \. l1 G% n4 D% F
public void spreadMoney(int money){, _9 f6 B9 h% D9 v1 P2 `: a6 X
    // Randomly place money in moneySpace1 @  c" J" r. c3 g, d2 B4 {8 j
    for(int i = 0; i < money; i++){
6 G$ E6 \* O3 M9 k1 z
' R8 d% v* ^9 j# R* b4 S- h      // Choose coordinates
' m1 M/ m0 h; o. p      int x = (int)(Math.random()*(moneySpace.getSizeX()));
$ _4 p1 s) F5 H, _7 a6 K& s7 u      int y = (int)(Math.random()*(moneySpace.getSizeY()));/ g9 V$ D) a4 q# q9 h( t

, b2 `- A4 R3 @) {7 Y      // Get the value of the object at those coordinates. [' I8 U0 f( a3 @& }% @
      int I;
1 x* ^+ f+ G! C2 T4 }( [      if(moneySpace.getObjectAt(x,y)!= null){7 l  a" L# Y% W  Y, C6 W0 i* j
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();: _4 i) U' W& J0 S0 U
      }. h' Z7 u& w8 d& P/ B- ^+ k
      else{
$ L: U' x+ _4 [4 d1 f+ j' `- T& p        I = 0;
& W0 j! |" Z4 y3 C' v# A      }
; B# y4 |2 g# ^- }+ |  E- m      // Replace the Integer object with another one with the new value
8 K% {, g' g7 z- z      moneySpace.putObjectAt(x,y,new Integer(I + 1));) K6 a& Z/ O9 r6 C. s8 `7 A
    }

3 h" j+ E: S5 _: `, }这里面if(moneySpace.getObjectAt(x,y)!= null){: _6 h- T* r/ n: g$ F' }
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
4 S# P; r# d) s! h* @      }
& q; P* s) X4 y: a      else{
" B: a1 N; l8 W' L        I = 0;

7 H4 q. \" F6 @5 I是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
$ ^0 _( L! E7 r# R) I. [( b( `3 k, g初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-25 22:49 , Processed in 0.013956 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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