设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4245|回复: 0

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

[复制链接]
发表于 2009-10-12 09:42:47 | 显示全部楼层 |阅读模式
大家都看过carrydrop的程序吧,里面设置moneyspce时将钱任意分布在空间中
5 L, k3 W! X. x6 e+ r% Q! r- R. tpublic void spreadMoney(int money){
) t$ @& e6 ], W5 O    // Randomly place money in moneySpace
8 L) D" D: e7 e0 T    for(int i = 0; i < money; i++){0 @. K: D/ W, V. s% b- g  {
" [( B. l% F: q# d/ n' V
      // Choose coordinates
! W0 j5 ^9 ^- |) k- ?3 U      int x = (int)(Math.random()*(moneySpace.getSizeX()));" v$ F+ j, U7 J4 z7 o' U8 B
      int y = (int)(Math.random()*(moneySpace.getSizeY()));+ D9 g2 a+ G+ q8 ?& U' Z  U" p
' S- h5 _, ~  d, N5 [
      // Get the value of the object at those coordinates
( y; O9 e3 ?+ C! O' `3 n      int I;
3 M, Y: I+ c! S1 W* {; m+ U      if(moneySpace.getObjectAt(x,y)!= null){
  L7 p9 U. P2 U$ Q; W' h        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();% }# @$ J" l1 v/ m
      }' Y( p/ W& R" [$ a4 R1 I
      else{  X9 W) q5 @2 O, K& Q
        I = 0;
  C" W! D8 s9 K" L* r      }# K, R9 i5 }) [" @$ l; N! x- Y5 }
      // Replace the Integer object with another one with the new value
, g& ?1 h0 K* y0 t0 ~: W. e      moneySpace.putObjectAt(x,y,new Integer(I + 1));
/ v6 Y1 `' G9 N    }

- W- v; J% S  D这里面if(moneySpace.getObjectAt(x,y)!= null){+ s$ P+ ?! d8 y* Z2 Z
        I = ((Integer)moneySpace.getObjectAt(x,y)).intValue();
- y6 c! ^1 e/ z) F4 R% A+ H- u' {      }0 @( L! p+ M/ B4 a& S4 t2 Z
      else{3 ^0 j# Y. K, p
        I = 0;

: `; X; J+ V8 W/ }$ c是在干什么啊?为什么后面的moneySpace.putObjectAt(x,y,new Integer(I + 1));要用new Integer(I + 1),这都在原来钱的基础上加一啊,我怎么看不出来是随意放置钱财的呢?' q* e' w6 u& F0 k3 u
初学者,还请见谅!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-22 06:48 , Processed in 0.016994 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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