设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5117|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中5 T1 u4 W. G4 E7 O4 ]( v8 |; R# t
public void spreadMoney(int money){
" c$ g. O  L* V    // Randomly place money in moneySpace
! n8 ~9 f; I# s" B$ d    for(int i = 0; i < money; i++){
  V$ O$ I; ]2 y
7 R# C# {! I' K5 O" J      // Choose coordinates: l8 t9 y" d& F7 s
      int x = (int)(Math.random()*(moneySpace.getSizeX()));0 _% S8 y2 X6 t
      int y = (int)(Math.random()*(moneySpace.getSizeY()));; P$ Y' Q# k7 Y% b
! Q( F7 E0 K6 v7 T
      // Get the value of the object at those coordinates
* L9 z  ]1 m: K2 O      int I;
5 b" E9 g3 ~: V( g      if(moneySpace.getObjectAt(x,y)!= null){* ~* c% F! J9 F4 f+ m
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
1 _5 y, `- v1 h! e; ]( a' P      }; {: |2 l. @3 @
      else{
" N7 k( d# ?  Q( Z3 z        I = 0;
) `9 G* b3 B, [2 n( t5 e8 c! M      }
6 Z* y- ]  v8 O+ D  _) u      // Replace the Integer object with another one with the new value0 W8 w% K" p7 d2 K
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
6 `% a) W4 f& j: |  m- h; k    }
7 P2 }: ]' S4 B; W
这里面if(moneySpace.getObjectAt(x,y)!= null){3 G1 i" i5 X, g
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();4 C2 u. e  y$ G
      }2 Z7 }" R8 w% t; n0 g  X
      else{
7 D7 n* u/ ]3 Z7 M* l7 y        I = 0;

3 F& E$ A  Y8 x& a& B+ |* _$ @( c是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?% s* W' T  R  U; O3 S
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-2 23:41 , Processed in 0.016381 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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