设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4437|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中* t' Q8 J5 p. Z0 A( E7 n7 c" X. [) q
public void spreadMoney(int money){
/ \7 ?5 J1 |. E- [! H: {2 c- j4 r    // Randomly place money in moneySpace
' a  ?+ U0 K' l- e9 p; N9 ]" P    for(int i = 0; i < money; i++){
, i' ?$ u* _) x4 x$ L# M; a! A$ q' Z( t- c1 Y
      // Choose coordinates
% Y0 Z1 ~0 T8 g7 J! B& o# L      int x = (int)(Math.random()*(moneySpace.getSizeX()));
$ |; T/ ^, i" d" l! @: R, H      int y = (int)(Math.random()*(moneySpace.getSizeY()));
0 [( c' j, l/ s, X" r6 Q' J& d# r/ k4 k- l3 U3 r6 H
      // Get the value of the object at those coordinates- o( `# @4 j6 M0 k
      int I;$ x2 ~( d6 e2 O- a/ \( e) I5 p
      if(moneySpace.getObjectAt(x,y)!= null){9 s, ^3 C( e; l5 s9 C
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
/ M  i. Z7 Q5 t& l& \- A' @      }
7 \% E' l  @: E* M. a' V! K      else{$ Q% D3 |" R/ j# k- m' W+ S
        I = 0;
6 E0 ^/ A0 M- N$ P0 q" a) t$ `' t      }
2 z  x  `5 s8 W9 T9 H2 d* D6 J      // Replace the Integer object with another one with the new value( u0 N5 R9 i3 A# y) A7 \0 x1 C
      moneySpace.putObjectAt(x,y,new Integer(I + 1));
! z2 {7 N) V/ E0 s9 Y3 L    }

& @! ?9 e: _  N9 H' O这里面if(moneySpace.getObjectAt(x,y)!= null){
% a2 A* B5 T! y7 `        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
! `2 D, R! g. G, H% i8 m- c      }
: Y4 a9 }1 O- |      else{
6 L- a9 Z* f# q  ?& b2 R        I = 0;
% n  w5 e! [* X: m
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?4 ?- z$ d8 a1 n  M7 }4 R
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-9 11:13 , Processed in 0.012412 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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