设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4476|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中0 D" h+ I. `3 @8 h9 D$ |$ D6 \
public void spreadMoney(int money){5 j6 K0 q  _7 m
    // Randomly place money in moneySpace
1 Y6 J4 P3 @& U! v& |% O    for(int i = 0; i < money; i++){
- p/ p8 s; t1 e/ c$ @& z, V, _  F, o$ C( B
      // Choose coordinates) w  F+ `1 r6 n+ h/ h6 Q
      int x = (int)(Math.random()*(moneySpace.getSizeX()));
0 K8 f) a/ K! x3 ^7 ?& j" f      int y = (int)(Math.random()*(moneySpace.getSizeY()));
% _- E  a/ n: h& K. }7 w8 I7 p9 g$ c$ }, e
      // Get the value of the object at those coordinates
+ C4 Z2 G& ]& m3 f$ p- M, D      int I;
3 }- V* ~/ V9 V      if(moneySpace.getObjectAt(x,y)!= null){
8 o( `0 c  D0 E0 W6 a6 |        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();7 A( O, Q6 n5 x% C5 d8 g0 O9 N
      }
( G9 O1 t0 ~1 g, l  }6 ~4 \      else{
8 {4 ]# H: |" V$ }$ `        I = 0;1 p$ V* l# ^. N3 b9 S* ?7 Q* r
      }
4 |! |2 @! g+ Z  ~1 M3 s1 P      // Replace the Integer object with another one with the new value
4 u4 Y" w4 k2 @1 g2 g! H      moneySpace.putObjectAt(x,y,new Integer(I + 1));' W  i" G1 q% A- h
    }

  i& \- x0 v6 a" q这里面if(moneySpace.getObjectAt(x,y)!= null){
5 f4 ~1 z7 i3 g# A  K        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();3 N$ Q( r$ i" V: V3 b- `; C6 }
      }
7 n# X  h8 {( z      else{
9 H" I2 S# E( D/ f5 C" m        I = 0;
; L, j6 Z  W5 C, M! N7 F
是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?
1 E) e$ t0 K6 ?1 t8 h! ~初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-15 16:46 , Processed in 0.018613 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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