diff --git a/src/de/itsblue/ConnectFour/ConnectFour.java b/src/de/itsblue/ConnectFour/ConnectFour.java index 4c16236..8cdc47b 100644 --- a/src/de/itsblue/ConnectFour/ConnectFour.java +++ b/src/de/itsblue/ConnectFour/ConnectFour.java @@ -34,6 +34,8 @@ public class ConnectFour extends JFrame implements ActionListener { private ButtonRow buttonRow; + private int player = 0; + /** * Constructor */ @@ -74,9 +76,16 @@ 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 Toolkit.getDefaultToolkit().beep(); @@ -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; + } } /**