基本上,我目前正在尝试为 Android 制作一个黑白棋游戏,而我的 if 语句让我有点头疼,似乎如果条件适合不止一个,它只是通过其中一个语句的动作然后离开另一个。我的代码如下所示:
if (check[position] == 0
&& (check[position - 8] == 2
|| check[position + 8] == 2
|| check[position + 1] == 2
|| check[position - 1] == 2
|| check[position - 9] == 2
|| check[position + 9] == 2
|| check[position - 7] == 2 || check[position + 7] == 2)) {
if (check[position + 8] == 2) {
for (int i = position; i < 56; i += 8) {
if (check[i] == 1) {
for (int j = position; j < i; j += 8) {
check[j] = 1;
}
playerno = 2;
break;
} else
break;
}
} else if (check[position - 8] == 2) {
for (int i = position; i > 8; i -= 8) {
if (check[i] == 1) {
for (int j = position; j > i; j -= 8) {
check[j] = 1;
}
playerno = 2;
break;
} else
break;
}
} else if (check[position + 1] == 2) {
for (int i = position; i < board.length; i++) {
if (check[i] == 1) {
for (int j = position; j < i; j++) {
check[j] = 1;
}
playerno = 2;
break;
}
if (i == 7 || i == 15 || i == 23 || i == 31
|| i == 39 || i == 47 || i == 55
|| i == 63) {
break;
}
}
} else if (check[position - 1] == 2) {
for (int i = position; i > 0; i--) {
if (check[i] == 1) {
for (int j = position; j > i; j--) {
check[j] = 1;
}
playerno = 2;
break;
}
if (i == 0 || i == 8 || i == 16 || i == 24
|| i == 32 || i == 40 || i == 48
|| i == 56) {
break;
}
}
}
Check 只是一个 int 数组,它记录了哪个玩家在棋盘上持有该特定棋子 现在,由于某种原因,如果我的位置满足其中两个条件,它只会通过一个 if 语句,而且通常这会产生游戏将其视为无效的举动,我想知道如何解决这个问题?