Added last winning condition check

Signed-off-by: Malte Tammena <malte.tammena@gmx.de>
This commit is contained in:
Malte Tammena 2017-10-15 12:21:39 +02:00
parent 8839a61ae5
commit f7c348b6ce

View file

@ -218,7 +218,59 @@ public class Game {
break outer; break outer;
} }
} }
// TODO: Finish other diagonals reverse = false;
count1 = 0;
count2 = 0;
posX = GAME_COLUMNS;
posY = 1;
addX = -1;
addY = -1;
outer:while (posX != 0 || posY != GAME_ROWS - 1) {
posX += addX;
posY += addY;
if (posX < 0) {
posY += 2;
posX = 0;
reverse = true;
} else if (posY > GAME_ROWS - 1) {
posX -= 2;
posY = GAME_ROWS - 1;
reverse = true;
} else if (posX > GAME_COLUMNS - 1) {
posX = GAME_COLUMNS - 1;
reverse = true;
} else if (posY < 0) {
posY = 0;
reverse = true;
}
if (reverse) {
addX *= -1;
addY *= -1;
count1 = 0;
count2 = 0;
reverse = false;
}
if (this.board[posX][posY] == 1) {
count1++;
count2 = 0;
} else if (this.board[posX][posY] == 2) {
count1 = 0;
count2++;
} else {
count1 = 0;
count2 = 0;
}
if (count1 >= 4) {
log("Player 1 won!");
this.gameOn = false;
break outer;
}
if (count2 >= 4) {
log("Player 2 won!");
this.gameOn = false;
break outer;
}
}
// --- CHECK DRAW --- // --- CHECK DRAW ---
boolean draw = true; boolean draw = true;