Browse Source

Bugfix draw order

feature_TicTacToe_Playfield
kfkama 3 years ago
parent
commit
848a5ba499
  1. 6
      src/main/java/TicTacToe/Cell.java
  2. 8
      src/main/java/TicTacToe/TicTacToeGame.java

6
src/main/java/TicTacToe/Cell.java

@ -41,12 +41,12 @@ public class Cell extends JButton {
g2.setPaint(Color.white); g2.setPaint(Color.white);
switch (playerID) { switch (playerID) {
case 1: case 1:
g2.drawOval(5, 5, 90, 90);
break;
case 2:
g2.drawLine(5, 5, 90, 90); g2.drawLine(5, 5, 90, 90);
g2.drawLine(90, 5, 5, 90); g2.drawLine(90, 5, 5, 90);
break; break;
case 2:
g2.drawOval(5, 5, 90, 90);
break;
} }
} }

8
src/main/java/TicTacToe/TicTacToeGame.java

@ -88,10 +88,9 @@ public class TicTacToeGame extends JPanel {
JOptionPane.showMessageDialog(getParent(),"Player: " + playerID + " Wins!"); JOptionPane.showMessageDialog(getParent(),"Player: " + playerID + " Wins!");
scoreboard.addPoint(playerID); scoreboard.addPoint(playerID);
resetGame(); resetGame();
}
} else {
turns++; turns++;
if(turns > playFieldSize) {
if(turns >= playFieldSize) {
JOptionPane.showMessageDialog(getParent(),"Draw!"); JOptionPane.showMessageDialog(getParent(),"Draw!");
scoreboard.addPoint(0); scoreboard.addPoint(0);
resetGame(); resetGame();
@ -103,6 +102,9 @@ public class TicTacToeGame extends JPanel {
} }
} }
}
public int checkPlayfield() { public int checkPlayfield() {
if ((field[0].playerID == playerID && field[1].playerID == playerID && field[2].playerID == playerID) if ((field[0].playerID == playerID && field[1].playerID == playerID && field[2].playerID == playerID)
|| (field[0].playerID == playerID && field[3].playerID == playerID && field[6].playerID == playerID) || (field[0].playerID == playerID && field[3].playerID == playerID && field[6].playerID == playerID)

Loading…
Cancel
Save