diff --git a/src/main/java/game/StartTicTacToeGame.java b/src/main/java/game/StartTicTacToeGame.java index e8b4557..221c8eb 100644 --- a/src/main/java/game/StartTicTacToeGame.java +++ b/src/main/java/game/StartTicTacToeGame.java @@ -157,6 +157,7 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); button.setEnabled(false); player1buttonPressed = true; + check(); } else { button.setForeground(Color.black); @@ -165,6 +166,7 @@ public class StartTicTacToeGame implements ActionListener{ button.setEnabled(false); player1Turn(); player2buttonPressed = true; + check(); } } else if(e.getSource() == button2) { @@ -175,6 +177,7 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); button2.setEnabled(false); player1button2Pressed = true; + check(); } else { button2.setForeground(Color.black); @@ -183,6 +186,7 @@ public class StartTicTacToeGame implements ActionListener{ button2.setEnabled(false); player1Turn(); player2button2Pressed = true; + check(); } } else if(e.getSource() == button3) { @@ -193,6 +197,7 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); button3.setEnabled(false); player1button3Pressed = true; + check(); } else { button3.setForeground(Color.black); @@ -201,6 +206,7 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); button3.setEnabled(false); player2button3Pressed = true; + check(); } } else if(e.getSource() == button4) { @@ -211,6 +217,7 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); button4.setEnabled(false); player1button4Pressed = true; + check(); } else { button4.setForeground(Color.black); @@ -219,6 +226,7 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); button4.setEnabled(false); player2button4Pressed = true; + check(); } } else if(e.getSource() == button5) { @@ -229,6 +237,7 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); button5.setEnabled(false); player1button5Pressed = true; + check(); } else { button5.setForeground(Color.black); @@ -237,6 +246,7 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); button5.setEnabled(false); player2button5Pressed = true; + check(); } } else if(e.getSource() == button6) { @@ -247,6 +257,7 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); button6.setEnabled(false); player1button6Pressed = true; + check(); } else { button6.setForeground(Color.black); @@ -255,6 +266,7 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); button6.setEnabled(false); player2button6Pressed = true; + check(); } } else if(e.getSource() == button7) { @@ -265,6 +277,7 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); button7.setEnabled(false); player1button7Pressed = true; + check(); } else { button7.setForeground(Color.black); @@ -273,6 +286,7 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); button7.setEnabled(false); player2button7Pressed = true; + check(); } } else if(e.getSource() == button8) { @@ -283,6 +297,7 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); button8.setEnabled(false); player1button8Pressed = true; + check(); } else { button8.setForeground(Color.black); @@ -291,6 +306,7 @@ public class StartTicTacToeGame implements ActionListener{ player1Turn(); button8.setEnabled(false); player2button8Pressed = true; + check(); } } else if(e.getSource() == button9) { @@ -301,6 +317,7 @@ public class StartTicTacToeGame implements ActionListener{ player2Turn(); button9.setEnabled(false); player1button9Pressed = true; + check(); } else { button9.setForeground(Color.black); @@ -309,6 +326,7 @@ public class StartTicTacToeGame implements ActionListener{ button9.setEnabled(false); player1Turn(); player2button9Pressed = true; + check(); } } @@ -346,4 +364,62 @@ public class StartTicTacToeGame implements ActionListener{ //zurück button backButton.setVisible(true); } + + public void check() { + if(player1buttonPressed && player1button2Pressed && player1button3Pressed) { + player1Won(); + } + else if(player1button4Pressed && player1button5Pressed && player1button6Pressed) { + player1Won(); + } + else if(player1button7Pressed && player1button8Pressed && player1button9Pressed) { + player1Won(); + } + else if(player1buttonPressed && player1button5Pressed && player1button6Pressed) { + player1Won(); + } + else if(player1buttonPressed && player1button4Pressed && player1button7Pressed) { + player1Won(); + } + else if(player1button2Pressed && player1button5Pressed && player1button8Pressed) { + player1Won(); + } + else if(player1button3Pressed && player1button6Pressed && player1button9Pressed) { + player1Won(); + } + else if(player1buttonPressed && player1button5Pressed && player1button9Pressed) { + player1Won(); + } + else if(player1button3Pressed && player1button5Pressed && player1button7Pressed) { + player1Won(); + } + + if(player2buttonPressed && player2button2Pressed && player2button3Pressed) { + player2Won(); + } + else if(player2button4Pressed && player2button5Pressed && player2button6Pressed) { + player2Won(); + } + else if(player2button7Pressed && player2button8Pressed && player2button9Pressed) { + player2Won(); + } + else if(player2buttonPressed && player2button5Pressed && player2button6Pressed) { + player2Won(); + } + else if(player2buttonPressed && player2button4Pressed && player2button7Pressed) { + player2Won(); + } + else if(player2button2Pressed && player2button5Pressed && player2button8Pressed) { + player2Won(); + } + else if(player2button3Pressed && player2button6Pressed && player2button9Pressed) { + player2Won(); + } + else if(player2buttonPressed && player2button5Pressed && player2button9Pressed) { + player2Won(); + } + else if(player2button3Pressed && player2button5Pressed && player2button7Pressed) { + player2Won(); + } + } } \ No newline at end of file