Merge branch 'fix-output' into 'master'

Fixing winner being called Player 1/2.

See merge request !9
This commit is contained in:
Malte Tammena 2017-10-16 11:18:17 +02:00
commit 9245101b2c

View file

@ -145,13 +145,15 @@ public class Game {
// --- CHECK WIN ---
// Check rows
outer:for (int i = 0; i < GAME_COLUMNS; i++) {
// Player One's counter
int count1 = 0;
// Player Two's counter
int count2 = 0;
for (int j = 0; j < GAME_ROWS; j++) {
if (this.board[i][j] == 1) {
if (this.board[i][j] == p1.getID()) {
count1++;
count2 = 0;
} else if (this.board[i][j] == 2) {
} else if (this.board[i][j] == p2.getID()) {
count1 = 0;
count2++;
} else {
@ -159,12 +161,12 @@ public class Game {
count2 = 0;
}
if (count1 >= 4) {
log("Player 1 won!");
log(p1.getP().getName() + " won!");
this.gameOn = false;
break outer;
}
if (count2 >= 4) {
log("Player 2 won!");
log(p2.getP().getName() + " won!");
this.gameOn = false;
break outer;
}
@ -172,13 +174,15 @@ public class Game {
}
// Check columns
outer:for (int j = 0; j < GAME_ROWS; j++) {
// Player One's counter
int count1 = 0;
// Player Two's counter
int count2 = 0;
for (int i = 0; i < GAME_COLUMNS; i++) {
if (this.board[i][j] == 1) {
if (this.board[i][j] == p1.getID()) {
count1++;
count2 = 0;
} else if (this.board[i][j] == 2) {
} else if (this.board[i][j] == p2.getID()) {
count1 = 0;
count2++;
} else {
@ -186,12 +190,12 @@ public class Game {
count2 = 0;
}
if (count1 >= 4) {
log("Player 1 won!");
log(p1.getP().getName() + " won!");
this.gameOn = false;
break outer;
}
if (count2 >= 4) {
log("Player 2 won!");
log(p2.getP().getName() + " won!");
this.gameOn = false;
break outer;
}
@ -228,10 +232,10 @@ public class Game {
count2 = 0;
reverse = false;
}
if (this.board[posX][posY] == 1) {
if (this.board[posX][posY] == p1.getID()) {
count1++;
count2 = 0;
} else if (this.board[posX][posY] == 2) {
} else if (this.board[posX][posY] == p2.getID()) {
count1 = 0;
count2++;
} else {
@ -239,12 +243,12 @@ public class Game {
count2 = 0;
}
if (count1 >= 4) {
log("Player 1 won!");
log(p1.getP().getName() + " won!");
this.gameOn = false;
break outer;
}
if (count2 >= 4) {
log("Player 2 won!");
log(p2.getP().getName() + " won!");
this.gameOn = false;
break outer;
}
@ -282,10 +286,10 @@ public class Game {
count2 = 0;
reverse = false;
}
if (this.board[posX][posY] == 1) {
if (this.board[posX][posY] == p1.getID()) {
count1++;
count2 = 0;
} else if (this.board[posX][posY] == 2) {
} else if (this.board[posX][posY] == p2.getID()) {
count1 = 0;
count2++;
} else {
@ -293,12 +297,12 @@ public class Game {
count2 = 0;
}
if (count1 >= 4) {
log("Player 1 won!");
log(p1.getP().getName() + " won!");
this.gameOn = false;
break outer;
}
if (count2 >= 4) {
log("Player 2 won!");
log(p2.getP().getName() + " won!");
this.gameOn = false;
break outer;
}