|
|
@ -16,7 +16,7 @@ public class TicTacToeGame extends JPanel { |
|
|
|
private static final int maxPlayers = 3; |
|
|
|
private static final int playFieldSize = 9; |
|
|
|
|
|
|
|
public cell[] field; |
|
|
|
public Cell[] field; |
|
|
|
public int playerID = 1; |
|
|
|
public int turns = 0; |
|
|
|
public Scoreboard scoreboard; |
|
|
@ -25,11 +25,10 @@ public class TicTacToeGame extends JPanel { |
|
|
|
this.setSize(width, height); |
|
|
|
setLayout(null); |
|
|
|
initField(); |
|
|
|
scoreboard = new Scoreboard(maxPlayers); |
|
|
|
scoreboard.setBounds(200, 100, 200, 50); |
|
|
|
add(scoreboard); |
|
|
|
initScoreboard(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
JFrame f = new JFrame(); |
|
|
|
TicTacToeGame ttt = new TicTacToeGame(); |
|
|
@ -41,10 +40,10 @@ public class TicTacToeGame extends JPanel { |
|
|
|
} |
|
|
|
|
|
|
|
public void initField() { |
|
|
|
field = new cell[playFieldSize]; |
|
|
|
field = new Cell[playFieldSize]; |
|
|
|
|
|
|
|
for(int i = 0; i < field.length; i++) { |
|
|
|
field[i] = new cell(this); |
|
|
|
field[i] = new Cell(this); |
|
|
|
add(field[i]); |
|
|
|
} |
|
|
|
|
|
|
@ -59,6 +58,12 @@ public class TicTacToeGame extends JPanel { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void initScoreboard() { |
|
|
|
scoreboard = new Scoreboard(maxPlayers); |
|
|
|
scoreboard.setBounds(200, 100, 200, 50); |
|
|
|
add(scoreboard); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void paintComponent(Graphics g) { |
|
|
|
super.paintComponent(g); |
|
|
@ -85,7 +90,7 @@ public class TicTacToeGame extends JPanel { |
|
|
|
turns++; |
|
|
|
if(turns >= playFieldSize) { |
|
|
|
JOptionPane.showMessageDialog(getParent(),"Draw!"); |
|
|
|
scoreboard.addPoint(playerID); |
|
|
|
scoreboard.addPoint(0); |
|
|
|
resetGame(); |
|
|
|
} |
|
|
|
|
|
|
@ -113,7 +118,7 @@ public class TicTacToeGame extends JPanel { |
|
|
|
} |
|
|
|
|
|
|
|
public void resetGame() { |
|
|
|
for (cell c : field) { |
|
|
|
for (Cell c : field) { |
|
|
|
c.reset(); |
|
|
|
} |
|
|
|
playerID = 1; |
|
|
|