|
@ -141,7 +141,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player2Turn(); |
|
|
player2Turn(); |
|
|
fieldButton.setEnabled(false); |
|
|
fieldButton.setEnabled(false); |
|
|
player1fieldButtonPressed = true; |
|
|
player1fieldButtonPressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
fieldButton.setForeground(Color.black); |
|
|
fieldButton.setForeground(Color.black); |
|
@ -150,7 +151,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
fieldButton.setEnabled(false); |
|
|
fieldButton.setEnabled(false); |
|
|
player1Turn(); |
|
|
player1Turn(); |
|
|
player2fieldButtonPressed = true; |
|
|
player2fieldButtonPressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if(e.getSource() == fieldButton2) { |
|
|
else if(e.getSource() == fieldButton2) { |
|
@ -161,7 +163,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player2Turn(); |
|
|
player2Turn(); |
|
|
fieldButton2.setEnabled(false); |
|
|
fieldButton2.setEnabled(false); |
|
|
player1fieldButton2Pressed = true; |
|
|
player1fieldButton2Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
fieldButton2.setForeground(Color.black); |
|
|
fieldButton2.setForeground(Color.black); |
|
@ -170,7 +173,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
fieldButton2.setEnabled(false); |
|
|
fieldButton2.setEnabled(false); |
|
|
player1Turn(); |
|
|
player1Turn(); |
|
|
player2fieldButton2Pressed = true; |
|
|
player2fieldButton2Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if(e.getSource() == fieldButton3) { |
|
|
else if(e.getSource() == fieldButton3) { |
|
@ -181,7 +185,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player2Turn(); |
|
|
player2Turn(); |
|
|
fieldButton3.setEnabled(false); |
|
|
fieldButton3.setEnabled(false); |
|
|
player1fieldButton3Pressed = true; |
|
|
player1fieldButton3Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
fieldButton3.setForeground(Color.black); |
|
|
fieldButton3.setForeground(Color.black); |
|
@ -190,7 +195,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player1Turn(); |
|
|
player1Turn(); |
|
|
fieldButton3.setEnabled(false); |
|
|
fieldButton3.setEnabled(false); |
|
|
player2fieldButton3Pressed = true; |
|
|
player2fieldButton3Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if(e.getSource() == fieldButton4) { |
|
|
else if(e.getSource() == fieldButton4) { |
|
@ -201,7 +207,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player2Turn(); |
|
|
player2Turn(); |
|
|
fieldButton4.setEnabled(false); |
|
|
fieldButton4.setEnabled(false); |
|
|
player1fieldButton4Pressed = true; |
|
|
player1fieldButton4Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
fieldButton4.setForeground(Color.black); |
|
|
fieldButton4.setForeground(Color.black); |
|
@ -210,7 +217,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player1Turn(); |
|
|
player1Turn(); |
|
|
fieldButton4.setEnabled(false); |
|
|
fieldButton4.setEnabled(false); |
|
|
player2fieldButton4Pressed = true; |
|
|
player2fieldButton4Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if(e.getSource() == fieldButton5) { |
|
|
else if(e.getSource() == fieldButton5) { |
|
@ -221,7 +229,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player2Turn(); |
|
|
player2Turn(); |
|
|
fieldButton5.setEnabled(false); |
|
|
fieldButton5.setEnabled(false); |
|
|
player1fieldButton5Pressed = true; |
|
|
player1fieldButton5Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
fieldButton5.setForeground(Color.black); |
|
|
fieldButton5.setForeground(Color.black); |
|
@ -230,7 +239,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player1Turn(); |
|
|
player1Turn(); |
|
|
fieldButton5.setEnabled(false); |
|
|
fieldButton5.setEnabled(false); |
|
|
player2fieldButton5Pressed = true; |
|
|
player2fieldButton5Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if(e.getSource() == fieldButton6) { |
|
|
else if(e.getSource() == fieldButton6) { |
|
@ -241,7 +251,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player2Turn(); |
|
|
player2Turn(); |
|
|
fieldButton6.setEnabled(false); |
|
|
fieldButton6.setEnabled(false); |
|
|
player1fieldButton6Pressed = true; |
|
|
player1fieldButton6Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
fieldButton6.setForeground(Color.black); |
|
|
fieldButton6.setForeground(Color.black); |
|
@ -250,7 +261,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player1Turn(); |
|
|
player1Turn(); |
|
|
fieldButton6.setEnabled(false); |
|
|
fieldButton6.setEnabled(false); |
|
|
player2fieldButton6Pressed = true; |
|
|
player2fieldButton6Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if(e.getSource() == fieldButton7) { |
|
|
else if(e.getSource() == fieldButton7) { |
|
@ -261,7 +273,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player2Turn(); |
|
|
player2Turn(); |
|
|
fieldButton7.setEnabled(false); |
|
|
fieldButton7.setEnabled(false); |
|
|
player1fieldButton7Pressed = true; |
|
|
player1fieldButton7Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
fieldButton7.setForeground(Color.black); |
|
|
fieldButton7.setForeground(Color.black); |
|
@ -270,7 +283,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player1Turn(); |
|
|
player1Turn(); |
|
|
fieldButton7.setEnabled(false); |
|
|
fieldButton7.setEnabled(false); |
|
|
player2fieldButton7Pressed = true; |
|
|
player2fieldButton7Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if(e.getSource() == fieldButton8) { |
|
|
else if(e.getSource() == fieldButton8) { |
|
@ -281,7 +295,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player2Turn(); |
|
|
player2Turn(); |
|
|
fieldButton8.setEnabled(false); |
|
|
fieldButton8.setEnabled(false); |
|
|
player1fieldButton8Pressed = true; |
|
|
player1fieldButton8Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
fieldButton8.setForeground(Color.black); |
|
|
fieldButton8.setForeground(Color.black); |
|
@ -290,7 +305,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player1Turn(); |
|
|
player1Turn(); |
|
|
fieldButton8.setEnabled(false); |
|
|
fieldButton8.setEnabled(false); |
|
|
player2fieldButton8Pressed = true; |
|
|
player2fieldButton8Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if(e.getSource() == fieldButton9) { |
|
|
else if(e.getSource() == fieldButton9) { |
|
@ -301,7 +317,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
player2Turn(); |
|
|
player2Turn(); |
|
|
fieldButton9.setEnabled(false); |
|
|
fieldButton9.setEnabled(false); |
|
|
player1fieldButton9Pressed = true; |
|
|
player1fieldButton9Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
fieldButton9.setForeground(Color.black); |
|
|
fieldButton9.setForeground(Color.black); |
|
@ -310,7 +327,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
fieldButton9.setEnabled(false); |
|
|
fieldButton9.setEnabled(false); |
|
|
player1Turn(); |
|
|
player1Turn(); |
|
|
player2fieldButton9Pressed = true; |
|
|
player2fieldButton9Pressed = true; |
|
|
check(); |
|
|
|
|
|
|
|
|
checkIfPlayer1Won(); |
|
|
|
|
|
checkIfPlayer2Won(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -349,7 +367,7 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
backButton.setVisible(true); |
|
|
backButton.setVisible(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void check() { |
|
|
|
|
|
|
|
|
public void checkIfPlayer1Won() { |
|
|
if(player1fieldButtonPressed && player1fieldButton2Pressed && player1fieldButton3Pressed) { |
|
|
if(player1fieldButtonPressed && player1fieldButton2Pressed && player1fieldButton3Pressed) { |
|
|
player1WonTheGame(); |
|
|
player1WonTheGame(); |
|
|
} |
|
|
} |
|
@ -377,7 +395,8 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
else if(player1fieldButton3Pressed && player1fieldButton5Pressed && player1fieldButton7Pressed) { |
|
|
else if(player1fieldButton3Pressed && player1fieldButton5Pressed && player1fieldButton7Pressed) { |
|
|
player1WonTheGame(); |
|
|
player1WonTheGame(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
public void checkIfPlayer2Won() { |
|
|
if(player2fieldButtonPressed && player2fieldButton2Pressed && player2fieldButton3Pressed) { |
|
|
if(player2fieldButtonPressed && player2fieldButton2Pressed && player2fieldButton3Pressed) { |
|
|
player2WonTheGame(); |
|
|
player2WonTheGame(); |
|
|
} |
|
|
} |
|
@ -405,5 +424,7 @@ public class StartTicTacToeGame implements ActionListener{ |
|
|
else if(player2fieldButton3Pressed && player2fieldButton5Pressed && player2fieldButton7Pressed) { |
|
|
else if(player2fieldButton3Pressed && player2fieldButton5Pressed && player2fieldButton7Pressed) { |
|
|
player2WonTheGame(); |
|
|
player2WonTheGame(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |