首页>代码>java swing开发的2048小游戏>/2048游戏/src/_2048/Randompic.java
package _2048;

import java.awt.Point;
import java.util.ArrayList;
import java.util.Random;

/**
 * 用来随机出现图片的类
 * 
 * @author zzc
 * 
 */
public class Randompic {
	Random r;
	ArrayList<Point> list = new ArrayList<Point>();

	public Randompic() {
		r = new Random();
	}

	// 根据传入数组 为arr添加项
	public void Found(int arr[][]) {
		// 先清空数组
		list.removeAll(list);
		for (int i = 0; i < arr.length; i++)
			for (int j = 0; j < arr[i].length; j++) {
				if (arr[i][j] == -1) {
					Point p = new Point(i, j);
					list.add(p);
				}
			}
	}

	// 随机一个坐标 返回point
	public Point random() {
		if (list.size() > 0) {
			int n = r.nextInt(list.size());
			return list.get(n);
		} else
			return new Point(-1, -1);

	}

	// 随机一个数字 2或4
	public int randomInt() {
		int n = r.nextInt(12);
		if (n % 5 == 0)
			return 4;
		else
			return 2;
	}
}
最近下载更多
1112WHQ  LV7 2023年11月3日
双方各何必呢  LV13 2023年5月31日
huangzy  LV12 2023年4月6日
liangge2115  LV27 2021年12月14日
选了了  LV7 2021年12月13日
Demo1111  LV30 2021年12月8日
123aa21a  LV5 2021年6月23日
misamjsds  LV9 2021年6月3日
快乐小贝  LV4 2021年2月1日
段朝洪  LV15 2020年11月21日
最近浏览更多
7456321  LV1 4月22日
ClydeSon  LV5 2023年12月27日
微信网友_6793785677565952  LV1 2023年12月25日
lshlsh 2023年12月25日
暂无贡献等级
bangyiyang  LV2 2023年12月21日
1112WHQ  LV7 2023年11月3日
jiangneng666  LV2 2023年10月20日
412836806 2023年10月13日
暂无贡献等级
双方各何必呢  LV13 2023年5月31日
huangzy  LV12 2023年4月6日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友