Fixing winner being called Player 1/2.
Signed-off-by: Malte Tammena <malte.tammena@gmx.de>
This commit is contained in:
parent
b78978a02e
commit
9a32883dbd
|
@ -145,13 +145,15 @@ public class Game {
|
||||||
// --- CHECK WIN ---
|
// --- CHECK WIN ---
|
||||||
// Check rows
|
// Check rows
|
||||||
outer:for (int i = 0; i < GAME_COLUMNS; i++) {
|
outer:for (int i = 0; i < GAME_COLUMNS; i++) {
|
||||||
|
// Player One's counter
|
||||||
int count1 = 0;
|
int count1 = 0;
|
||||||
|
// Player Two's counter
|
||||||
int count2 = 0;
|
int count2 = 0;
|
||||||
for (int j = 0; j < GAME_ROWS; j++) {
|
for (int j = 0; j < GAME_ROWS; j++) {
|
||||||
if (this.board[i][j] == 1) {
|
if (this.board[i][j] == p1.getID()) {
|
||||||
count1++;
|
count1++;
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
} else if (this.board[i][j] == 2) {
|
} else if (this.board[i][j] == p2.getID()) {
|
||||||
count1 = 0;
|
count1 = 0;
|
||||||
count2++;
|
count2++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -159,12 +161,12 @@ public class Game {
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
}
|
}
|
||||||
if (count1 >= 4) {
|
if (count1 >= 4) {
|
||||||
log("Player 1 won!");
|
log(p1.getP().getName() + " won!");
|
||||||
this.gameOn = false;
|
this.gameOn = false;
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
if (count2 >= 4) {
|
if (count2 >= 4) {
|
||||||
log("Player 2 won!");
|
log(p2.getP().getName() + " won!");
|
||||||
this.gameOn = false;
|
this.gameOn = false;
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
|
@ -172,13 +174,15 @@ public class Game {
|
||||||
}
|
}
|
||||||
// Check columns
|
// Check columns
|
||||||
outer:for (int j = 0; j < GAME_ROWS; j++) {
|
outer:for (int j = 0; j < GAME_ROWS; j++) {
|
||||||
|
// Player One's counter
|
||||||
int count1 = 0;
|
int count1 = 0;
|
||||||
|
// Player Two's counter
|
||||||
int count2 = 0;
|
int count2 = 0;
|
||||||
for (int i = 0; i < GAME_COLUMNS; i++) {
|
for (int i = 0; i < GAME_COLUMNS; i++) {
|
||||||
if (this.board[i][j] == 1) {
|
if (this.board[i][j] == p1.getID()) {
|
||||||
count1++;
|
count1++;
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
} else if (this.board[i][j] == 2) {
|
} else if (this.board[i][j] == p2.getID()) {
|
||||||
count1 = 0;
|
count1 = 0;
|
||||||
count2++;
|
count2++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -186,12 +190,12 @@ public class Game {
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
}
|
}
|
||||||
if (count1 >= 4) {
|
if (count1 >= 4) {
|
||||||
log("Player 1 won!");
|
log(p1.getP().getName() + " won!");
|
||||||
this.gameOn = false;
|
this.gameOn = false;
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
if (count2 >= 4) {
|
if (count2 >= 4) {
|
||||||
log("Player 2 won!");
|
log(p2.getP().getName() + " won!");
|
||||||
this.gameOn = false;
|
this.gameOn = false;
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
|
@ -228,10 +232,10 @@ public class Game {
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
reverse = false;
|
reverse = false;
|
||||||
}
|
}
|
||||||
if (this.board[posX][posY] == 1) {
|
if (this.board[posX][posY] == p1.getID()) {
|
||||||
count1++;
|
count1++;
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
} else if (this.board[posX][posY] == 2) {
|
} else if (this.board[posX][posY] == p2.getID()) {
|
||||||
count1 = 0;
|
count1 = 0;
|
||||||
count2++;
|
count2++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -239,12 +243,12 @@ public class Game {
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
}
|
}
|
||||||
if (count1 >= 4) {
|
if (count1 >= 4) {
|
||||||
log("Player 1 won!");
|
log(p1.getP().getName() + " won!");
|
||||||
this.gameOn = false;
|
this.gameOn = false;
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
if (count2 >= 4) {
|
if (count2 >= 4) {
|
||||||
log("Player 2 won!");
|
log(p2.getP().getName() + " won!");
|
||||||
this.gameOn = false;
|
this.gameOn = false;
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
|
@ -282,10 +286,10 @@ public class Game {
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
reverse = false;
|
reverse = false;
|
||||||
}
|
}
|
||||||
if (this.board[posX][posY] == 1) {
|
if (this.board[posX][posY] == p1.getID()) {
|
||||||
count1++;
|
count1++;
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
} else if (this.board[posX][posY] == 2) {
|
} else if (this.board[posX][posY] == p2.getID()) {
|
||||||
count1 = 0;
|
count1 = 0;
|
||||||
count2++;
|
count2++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -293,12 +297,12 @@ public class Game {
|
||||||
count2 = 0;
|
count2 = 0;
|
||||||
}
|
}
|
||||||
if (count1 >= 4) {
|
if (count1 >= 4) {
|
||||||
log("Player 1 won!");
|
log(p1.getP().getName() + " won!");
|
||||||
this.gameOn = false;
|
this.gameOn = false;
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
if (count2 >= 4) {
|
if (count2 >= 4) {
|
||||||
log("Player 2 won!");
|
log(p2.getP().getName() + " won!");
|
||||||
this.gameOn = false;
|
this.gameOn = false;
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue