|
@ -19,11 +19,15 @@ public class TicTacToeGame extends JPanel { |
|
|
public cell[] field; |
|
|
public cell[] field; |
|
|
public int playerID = 1; |
|
|
public int playerID = 1; |
|
|
public int turns = 0; |
|
|
public int turns = 0; |
|
|
|
|
|
public Scoreboard scoreboard; |
|
|
|
|
|
|
|
|
public TicTacToeGame() { |
|
|
public TicTacToeGame() { |
|
|
this.setSize(width, height); |
|
|
this.setSize(width, height); |
|
|
setLayout(null); |
|
|
setLayout(null); |
|
|
initField(); |
|
|
initField(); |
|
|
|
|
|
scoreboard = new Scoreboard(maxPlayers); |
|
|
|
|
|
scoreboard.setBounds(200, 100, 200, 50); |
|
|
|
|
|
add(scoreboard); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
@ -74,12 +78,14 @@ public class TicTacToeGame extends JPanel { |
|
|
public void endTurn() { |
|
|
public void endTurn() { |
|
|
if(checkPlayfield() != 0) { |
|
|
if(checkPlayfield() != 0) { |
|
|
JOptionPane.showMessageDialog(getParent(),"Player: " + playerID + " Wins!"); |
|
|
JOptionPane.showMessageDialog(getParent(),"Player: " + playerID + " Wins!"); |
|
|
|
|
|
scoreboard.addPoint(playerID); |
|
|
resetGame(); |
|
|
resetGame(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
turns++; |
|
|
turns++; |
|
|
if(turns >= playFieldSize) { |
|
|
if(turns >= playFieldSize) { |
|
|
JOptionPane.showMessageDialog(getParent(),"Draw!"); |
|
|
JOptionPane.showMessageDialog(getParent(),"Draw!"); |
|
|
|
|
|
scoreboard.addPoint(playerID); |
|
|
resetGame(); |
|
|
resetGame(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|