added everytime player change
This commit is contained in:
parent
ef225e828b
commit
de3543513f
1 changed files with 27 additions and 2 deletions
|
@ -34,6 +34,8 @@ public class ConnectFour extends JFrame implements ActionListener {
|
|||
|
||||
private ButtonRow buttonRow;
|
||||
|
||||
private int player = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
@ -74,8 +76,15 @@ public class ConnectFour extends JFrame implements ActionListener {
|
|||
* @param column The column to insert the plate into
|
||||
*/
|
||||
private void insertNextPlate(int column) {
|
||||
// TODO: change player everytime
|
||||
String res = this.gameBoard.insertPlate(new Plate(PlateType.X), column);
|
||||
String res;
|
||||
|
||||
|
||||
|
||||
if (player == 0) {
|
||||
res = this.gameBoard.insertPlate(new Plate(PlateType.X), column);
|
||||
} else {
|
||||
res = this.gameBoard.insertPlate(new Plate(PlateType.O), column);
|
||||
}
|
||||
|
||||
if (res == "err") {
|
||||
// beep in case of error
|
||||
|
@ -84,6 +93,22 @@ public class ConnectFour extends JFrame implements ActionListener {
|
|||
PlateType winnerType = PlateType.valueOf(res);
|
||||
System.out.println("A player won: " + winnerType);
|
||||
}
|
||||
|
||||
switchPlayer();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function to switch the player
|
||||
*/
|
||||
private void switchPlayer() {
|
||||
if (player == 0) {
|
||||
player = 1;
|
||||
}
|
||||
else{
|
||||
player = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue