class Select {
private Select() {}
public static void caseSS(boolean[] lei, int[] guangBiao, int[] xianShi,
int[] slw, String ss, int[] winX, boolean[] b) // 对输入字符串进行判断,进行相应动作。
{
switch (ss) {
case "w":
Move.upW(lei, guangBiao, xianShi, slw);
break;
case "a":
Move.leftA(lei, guangBiao, xianShi, slw);
break;
case "s":
Move.downS(lei, guangBiao, xianShi, slw);
break;
case "d":
Move.rightD(lei, guangBiao, xianShi, slw);
break;
case "y": // 确定打开非雷区域,如果是雷,游戏失败。
y(lei, guangBiao, xianShi, slw, 1, winX, b);
break;
case "l": // 雷的确定并计数,如果非雷,游戏失败。
y(lei, guangBiao, xianShi, slw, 0, winX, b);
break;
default:
System.out
.println("请输入\"w、a、s、d\"进行移动,输入\"y\"显示非雷区,输入\"l(L小写)\"确定雷点。");
break;
}
JieMian.Print(lei, guangBiao, xianShi, slw);
return;
}
private static void y(boolean[] lei, int[] guangBiao, int[] xianShi,
int[] slw, int canShu, int[] winX, boolean[] b) {
switch (canShu) {
case 1: // 输入 y → case 1:
if (lei[guangBiao[0]] == true) {
System.out.println("哎呀,妈呀,你踩着雷了。\n");
b[0] = false;
return;
} else if (slw[guangBiao[0]] != 0) {
xianShi[guangBiao[0]] = -1;
} else {
int jiDian = guangBiao[0];
xianShi[guangBiao[0]] = -1;
kongBai(xianShi, jiDian); // 空白扩散。第一步。jiDian → 基点
//JieMian.Print(lei, guangBiao, xianShi, slw);
for (int i = 0; i < 81; i++) {
// slw[i]==0 → 空白处,lei[i]==false → 非雷区。
if (slw[i] == 0 && lei[i] == false) {
int[] wasd = FanWei.getWASD(i);
for (int ii = 0; ii < 8; ii++) {
if (xianShi[i + wasd[ii]] == -1 && wasd[ii] != 0
&& slw[i + wasd[ii]] == 0) {
// //调试扩散位置
// System.out.println("xianShi[i+wasd[ii]]"+xianShi[i+wasd[ii]]);
kongBai(xianShi, i + wasd[ii]);
// System.out.println("i+wasd[ii]="+(i+wasd[ii]));
}
}
}
}
for (int i = 80; i >= 0; i--) // 倒过来再运行一次,使扩散更广。
{
if (slw[i] == 0 && lei[i] == false) {
int[] wasd = FanWei.getWASD(i);
for (int ii = 0; ii < 8; ii++) {
if (xianShi[i + wasd[ii]] == -1 && wasd[ii] != 0
&& slw[i + wasd[ii]] == 0) {
// //调试扩散位置
// System.out.println("xianShi[i+wasd[ii]]"+xianShi[i+wasd[ii]]);
kongBai(xianShi, i + wasd[ii]);
// System.out.println("i+wasd[ii]="+(i+wasd[ii]));
}
}
}
}
}
break;
case 0: // 输入 l → case 0:
if (lei[guangBiao[0]] == true) {
if (xianShi[guangBiao[0]] != -1) {
xianShi[guangBiao[0]] = -1;
winX[0]++;
if (winX[0] == 10) // 如果已经胜利。
{
System.out.println("恭喜十个雷都已经找到!国家需要你这样的人才!");
b[0] = false; // 结束循环。
Victory.print();
System.exit(0);
return;
} else
System.out.println("恭喜找到" + winX[0] + "个雷,拆弹部队正在路上......");
}
} else {
System.out.println("抱歉,这里不是雷,游戏失败,请再接再厉。");
b[0] = false;
}
break;
default:
break;
}
return;
}
private static void kongBai(int[] xianShi, int jiDian) {
int wasd[] = FanWei.getWASD(jiDian); // 扩散范围。
for (int ii = 0; ii < 8; ii++) {
xianShi[jiDian + wasd[ii]] = -1;
}
}
}
|