设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4127|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
" o  E& d4 h* ?7 Q/ Npublic void spreadMoney(int money){0 i1 {) g2 ?; s. u5 p' P* k  a$ i% s
    // Randomly place money in moneySpace
% Z. u7 O4 J4 v3 Q' O, g    for(int i = 0; i < money; i++){
/ W: e$ B6 v7 V4 {6 _' x2 _+ ]/ l2 K. T+ N( z9 n2 f9 {: F
      // Choose coordinates
! s8 p; k$ j9 B$ D* z) n4 ]* z/ a      int x = (int)(Math.random()*(moneySpace.getSizeX()));
- m, f7 h, K# i) y/ _      int y = (int)(Math.random()*(moneySpace.getSizeY()));- M' b. a% W# x! E/ i0 u" b) ^
! M2 c, K* T8 O* G  q- j
      // Get the value of the object at those coordinates
  q( H2 K: f$ V      int I;; N6 O! Y/ _; U1 o9 D) R9 N
      if(moneySpace.getObjectAt(x,y)!= null){- m. G& l8 y7 H; G  p0 D& ]& |$ K
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();9 L8 X% k( r, k5 H* @
      }
! ?0 u' {8 A+ L7 w8 ]      else{
' |6 R5 n; I% O- L  @3 q5 i        I = 0;7 G: }- N7 s/ l/ ?3 Z# ]
      }+ S% O: f* I/ h" A
      // Replace the Integer object with another one with the new value! y2 C& y9 Z& e1 W
      moneySpace.putObjectAt(x,y,new Integer(I + 1));5 {9 G% S* a% B$ c
    }
1 u* h8 H$ w, y5 k$ e, n3 R
这里面if(moneySpace.getObjectAt(x,y)!= null){
8 v' D/ b7 X% F        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();; E) a$ o! [) t% v+ s/ ]
      }
' T; z+ |  |* W& S- k# R8 O; {7 A8 j      else{
% u4 H- e& j/ u        I = 0;

- B. Q) z5 q6 Q: z$ x是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
6 q" w9 ]7 |$ [% X, j9 F8 g初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-19 08:26 , Processed in 0.014722 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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