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 ButtonRow buttonRow;
|
||||||
|
|
||||||
|
private int player = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
@ -74,9 +76,16 @@ public class ConnectFour extends JFrame implements ActionListener {
|
||||||
* @param column The column to insert the plate into
|
* @param column The column to insert the plate into
|
||||||
*/
|
*/
|
||||||
private void insertNextPlate(int column) {
|
private void insertNextPlate(int column) {
|
||||||
// TODO: change player everytime
|
String res;
|
||||||
String res = this.gameBoard.insertPlate(new Plate(PlateType.X), column);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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") {
|
if (res == "err") {
|
||||||
// beep in case of error
|
// beep in case of error
|
||||||
Toolkit.getDefaultToolkit().beep();
|
Toolkit.getDefaultToolkit().beep();
|
||||||
|
@ -84,6 +93,22 @@ public class ConnectFour extends JFrame implements ActionListener {
|
||||||
PlateType winnerType = PlateType.valueOf(res);
|
PlateType winnerType = PlateType.valueOf(res);
|
||||||
System.out.println("A player won: " + winnerType);
|
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