设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4787|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中6 u' W# ]$ B- ?/ U4 g
public void spreadMoney(int money){$ p  \; q5 M  J3 ~$ z
    // Randomly place money in moneySpace
, E; ~. I5 _) l- C' @    for(int i = 0; i < money; i++){# v% r5 c7 }1 @$ Y" |" t

, g  k( r6 ?* s; |& |" w/ x      // Choose coordinates
% M" I# K8 A* Q      int x = (int)(Math.random()*(moneySpace.getSizeX()));: @$ `3 g" ?6 J* L/ f) f
      int y = (int)(Math.random()*(moneySpace.getSizeY()));
4 {. z* l* r2 b" i( A1 b
4 z- ~  s" S$ h  y6 y; O, T      // Get the value of the object at those coordinates
5 q* W, X# ^1 z, G      int I;
) O( a* J6 I9 v5 `. B& n( X+ Z4 G      if(moneySpace.getObjectAt(x,y)!= null){; G. |- N# C) l& o1 F* a5 x
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
6 }* g0 e7 O8 z  c      }
$ i  O' c* t7 D, U. |      else{
  A8 W5 t/ q0 ?5 P& {        I = 0;
9 g) V, v' ?( S  J      }- b+ ?4 h/ `4 m( [, X5 S3 Z4 f7 U
      // Replace the Integer object with another one with the new value& b1 f1 w- v3 j9 Z$ V, |
      moneySpace.putObjectAt(x,y,new Integer(I + 1));( i1 l5 Q% K2 X
    }

) g, p+ ]* G. o; k4 }6 s这里面if(moneySpace.getObjectAt(x,y)!= null){  w2 H+ x" d/ F" q
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();2 M2 u0 z0 W4 R+ A
      }
7 h# y2 ~; u' q* Q5 W      else{
- Q' P( _: k( }8 _; @        I = 0;

0 L2 u9 E9 W: x5 I; |) H9 e是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
  H4 Q' y2 ~& K; U初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-21 10:22 , Processed in 0.017168 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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