设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4105|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
$ P% P3 U9 p& G: Rpublic void spreadMoney(int money){
% O1 l; C  C; I( U; b& f    // Randomly place money in moneySpace
6 v0 g. }/ G; A    for(int i = 0; i < money; i++){
1 b+ U/ `" a4 }% Y
% X# u1 l- M" O$ ]7 A' s      // Choose coordinates
) h7 c3 Y( k. P- V% {$ U      int x = (int)(Math.random()*(moneySpace.getSizeX()));
; o; [; q: {- {' k5 h4 M      int y = (int)(Math.random()*(moneySpace.getSizeY()));
8 _: D0 D! k2 s( t0 U$ R: Z1 x+ S1 r/ b+ a/ \- k
      // Get the value of the object at those coordinates
- L$ J/ D/ h9 U& g0 @7 o. J      int I;
# E0 Q4 Y) y3 O- h4 Z8 Z      if(moneySpace.getObjectAt(x,y)!= null){
# R" u! n3 y2 m: Q6 n- X% a6 a, r        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
+ X6 B7 t! f! ]% B. M6 f* c      }; G7 E, l0 [( v, I. [
      else{6 o4 F: m$ e6 x: p* f! \+ H2 e/ \8 S
        I = 0;
& M$ s9 a  \4 T2 K1 |6 P  G( c      }
  E$ f3 F: J! C. A; J8 S      // Replace the Integer object with another one with the new value7 M+ h' @$ w: N! V+ T& e9 V. `! x
      moneySpace.putObjectAt(x,y,new Integer(I + 1));  M% V8 i( \3 W5 S( g2 L
    }
( Y  W' J. I- S- S% \
这里面if(moneySpace.getObjectAt(x,y)!= null){; E% Z6 U( @5 m8 r* k3 u+ J
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 W: F& M$ I! [3 `
      }8 |* s3 Z" l& [, n6 [
      else{- Z' T% w6 E0 k8 ~
        I = 0;

$ v3 D  }( M6 _. v- `3 g是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?, v3 e+ Q" ^! ]! V* d
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-15 01:24 , Processed in 0.019059 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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