Browse Source

refactoring: renamed player1button to player1fieldButton

master
TRC9696 2 years ago
parent
commit
934a23cc9f
  1. 46
      src/main/java/game/StartTicTacToeGame.java

46
src/main/java/game/StartTicTacToeGame.java

@ -17,11 +17,11 @@ public class StartTicTacToeGame implements ActionListener{
static JButton fieldButton,fieldButton2,fieldButton3,fieldButton4,
fieldButton5,fieldButton6,fieldButton7,fieldButton8,fieldButton9,backButton = new JButton();
boolean player1buttonPressed, player1button2Pressed,
player1button3Pressed, player1button4Pressed,
player1button5Pressed, player1button6Pressed,
player1button7Pressed, player1button8Pressed,
player1button9Pressed = false;
boolean player1fieldButtonPressed, player1fieldButton2Pressed,
player1fieldButton3Pressed, player1fieldButton4Pressed,
player1fieldButton5Pressed, player1fieldButton6Pressed,
player1fieldButton7Pressed, player1fieldButton8Pressed,
player1fieldButton9Pressed = false;
boolean player2buttonPressed, player2button2Pressed,
player2button3Pressed, player2button4Pressed,
@ -140,7 +140,7 @@ public class StartTicTacToeGame implements ActionListener{
fieldButton.setFont(new Font("arial", Font.PLAIN, 30));
player2Turn();
fieldButton.setEnabled(false);
player1buttonPressed = true;
player1fieldButtonPressed = true;
check();
}
else {
@ -160,7 +160,7 @@ public class StartTicTacToeGame implements ActionListener{
fieldButton2.setFont(new Font("arial", Font.PLAIN, 30));
player2Turn();
fieldButton2.setEnabled(false);
player1button2Pressed = true;
player1fieldButton2Pressed = true;
check();
}
else {
@ -180,7 +180,7 @@ public class StartTicTacToeGame implements ActionListener{
fieldButton3.setFont(new Font("arial", Font.PLAIN, 30));
player2Turn();
fieldButton3.setEnabled(false);
player1button3Pressed = true;
player1fieldButton3Pressed = true;
check();
}
else {
@ -200,7 +200,7 @@ public class StartTicTacToeGame implements ActionListener{
fieldButton4.setFont(new Font("arial", Font.PLAIN, 30));
player2Turn();
fieldButton4.setEnabled(false);
player1button4Pressed = true;
player1fieldButton4Pressed = true;
check();
}
else {
@ -220,7 +220,7 @@ public class StartTicTacToeGame implements ActionListener{
fieldButton5.setFont(new Font("arial", Font.PLAIN, 30));
player2Turn();
fieldButton5.setEnabled(false);
player1button5Pressed = true;
player1fieldButton5Pressed = true;
check();
}
else {
@ -240,7 +240,7 @@ public class StartTicTacToeGame implements ActionListener{
fieldButton6.setFont(new Font("arial", Font.PLAIN, 30));
player2Turn();
fieldButton6.setEnabled(false);
player1button6Pressed = true;
player1fieldButton6Pressed = true;
check();
}
else {
@ -260,7 +260,7 @@ public class StartTicTacToeGame implements ActionListener{
fieldButton7.setFont(new Font("arial", Font.PLAIN, 30));
player2Turn();
fieldButton7.setEnabled(false);
player1button7Pressed = true;
player1fieldButton7Pressed = true;
check();
}
else {
@ -280,7 +280,7 @@ public class StartTicTacToeGame implements ActionListener{
fieldButton8.setFont(new Font("arial", Font.PLAIN, 30));
player2Turn();
fieldButton8.setEnabled(false);
player1button8Pressed = true;
player1fieldButton8Pressed = true;
check();
}
else {
@ -300,7 +300,7 @@ public class StartTicTacToeGame implements ActionListener{
fieldButton9.setFont(new Font("arial", Font.PLAIN, 30));
player2Turn();
fieldButton9.setEnabled(false);
player1button9Pressed = true;
player1fieldButton9Pressed = true;
check();
}
else {
@ -350,31 +350,31 @@ public class StartTicTacToeGame implements ActionListener{
}
public void check() {
if(player1buttonPressed && player1button2Pressed && player1button3Pressed) {
if(player1fieldButtonPressed && player1fieldButton2Pressed && player1fieldButton3Pressed) {
player1Won();
}
else if(player1button4Pressed && player1button5Pressed && player1button6Pressed) {
else if(player1fieldButton4Pressed && player1fieldButton5Pressed && player1fieldButton6Pressed) {
player1Won();
}
else if(player1button7Pressed && player1button8Pressed && player1button9Pressed) {
else if(player1fieldButton7Pressed && player1fieldButton8Pressed && player1fieldButton9Pressed) {
player1Won();
}
else if(player1buttonPressed && player1button5Pressed && player1button6Pressed) {
else if(player1fieldButtonPressed && player1fieldButton5Pressed && player1fieldButton6Pressed) {
player1Won();
}
else if(player1buttonPressed && player1button4Pressed && player1button7Pressed) {
else if(player1fieldButtonPressed && player1fieldButton4Pressed && player1fieldButton7Pressed) {
player1Won();
}
else if(player1button2Pressed && player1button5Pressed && player1button8Pressed) {
else if(player1fieldButton2Pressed && player1fieldButton5Pressed && player1fieldButton8Pressed) {
player1Won();
}
else if(player1button3Pressed && player1button6Pressed && player1button9Pressed) {
else if(player1fieldButton3Pressed && player1fieldButton6Pressed && player1fieldButton9Pressed) {
player1Won();
}
else if(player1buttonPressed && player1button5Pressed && player1button9Pressed) {
else if(player1fieldButtonPressed && player1fieldButton5Pressed && player1fieldButton9Pressed) {
player1Won();
}
else if(player1button3Pressed && player1button5Pressed && player1button7Pressed) {
else if(player1fieldButton3Pressed && player1fieldButton5Pressed && player1fieldButton7Pressed) {
player1Won();
}

Loading…
Cancel
Save