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;
}
}
最近下载更多
最近浏览更多
2354593759
2024年12月31日
暂无贡献等级
qqqww11 LV2
2024年6月26日
鬼屋报道 LV3
2024年6月1日
7456321 LV1
2024年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日

