diff --git a/src/main/java/game/StartTicTacToeGame.java b/src/main/java/game/StartTicTacToeGame.java index 415932a..4335435 100644 --- a/src/main/java/game/StartTicTacToeGame.java +++ b/src/main/java/game/StartTicTacToeGame.java @@ -141,7 +141,8 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); fieldButton.setEnabled(false); player1fieldButtonPressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } else { fieldButton.setForeground(Color.black); @@ -150,7 +151,8 @@ public class StartTicTacToeGame implements ActionListener{ fieldButton.setEnabled(false); player1Turn(); player2fieldButtonPressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } } else if(e.getSource() == fieldButton2) { @@ -161,7 +163,8 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); fieldButton2.setEnabled(false); player1fieldButton2Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } else { fieldButton2.setForeground(Color.black); @@ -170,7 +173,8 @@ public class StartTicTacToeGame implements ActionListener{ fieldButton2.setEnabled(false); player1Turn(); player2fieldButton2Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } } else if(e.getSource() == fieldButton3) { @@ -181,7 +185,8 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); fieldButton3.setEnabled(false); player1fieldButton3Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } else { fieldButton3.setForeground(Color.black); @@ -190,7 +195,8 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); fieldButton3.setEnabled(false); player2fieldButton3Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } } else if(e.getSource() == fieldButton4) { @@ -201,7 +207,8 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); fieldButton4.setEnabled(false); player1fieldButton4Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } else { fieldButton4.setForeground(Color.black); @@ -210,7 +217,8 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); fieldButton4.setEnabled(false); player2fieldButton4Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } } else if(e.getSource() == fieldButton5) { @@ -221,7 +229,8 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); fieldButton5.setEnabled(false); player1fieldButton5Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } else { fieldButton5.setForeground(Color.black); @@ -230,7 +239,8 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); fieldButton5.setEnabled(false); player2fieldButton5Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } } else if(e.getSource() == fieldButton6) { @@ -241,7 +251,8 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); fieldButton6.setEnabled(false); player1fieldButton6Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } else { fieldButton6.setForeground(Color.black); @@ -250,7 +261,8 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); fieldButton6.setEnabled(false); player2fieldButton6Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } } else if(e.getSource() == fieldButton7) { @@ -261,7 +273,8 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); fieldButton7.setEnabled(false); player1fieldButton7Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } else { fieldButton7.setForeground(Color.black); @@ -270,7 +283,8 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); fieldButton7.setEnabled(false); player2fieldButton7Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } } else if(e.getSource() == fieldButton8) { @@ -281,7 +295,8 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); fieldButton8.setEnabled(false); player1fieldButton8Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } else { fieldButton8.setForeground(Color.black); @@ -290,7 +305,8 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); fieldButton8.setEnabled(false); player2fieldButton8Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } } else if(e.getSource() == fieldButton9) { @@ -301,7 +317,8 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); fieldButton9.setEnabled(false); player1fieldButton9Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } else { fieldButton9.setForeground(Color.black); @@ -310,7 +327,8 @@ public class StartTicTacToeGame implements ActionListener{ fieldButton9.setEnabled(false); player1Turn(); player2fieldButton9Pressed = true; - check(); + checkIfPlayer1Won(); + checkIfPlayer2Won(); } } @@ -349,7 +367,7 @@ public class StartTicTacToeGame implements ActionListener{ backButton.setVisible(true); } - public void check() { + public void checkIfPlayer1Won() { if(player1fieldButtonPressed && player1fieldButton2Pressed && player1fieldButton3Pressed) { player1WonTheGame(); } @@ -377,7 +395,8 @@ public class StartTicTacToeGame implements ActionListener{ else if(player1fieldButton3Pressed && player1fieldButton5Pressed && player1fieldButton7Pressed) { player1WonTheGame(); } - + } + public void checkIfPlayer2Won() { if(player2fieldButtonPressed && player2fieldButton2Pressed && player2fieldButton3Pressed) { player2WonTheGame(); } @@ -404,6 +423,8 @@ public class StartTicTacToeGame implements ActionListener{ } else if(player2fieldButton3Pressed && player2fieldButton5Pressed && player2fieldButton7Pressed) { player2WonTheGame(); + } + } - } -} \ No newline at end of file + + } \ No newline at end of file