|
@ -1,5 +1,6 @@ |
|
|
package TicTacToe; |
|
|
package TicTacToe; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
import java.awt.Graphics; |
|
|
import java.awt.Graphics; |
|
|
import java.awt.Graphics2D; |
|
|
import java.awt.Graphics2D; |
|
|
import java.awt.geom.Line2D; |
|
|
import java.awt.geom.Line2D; |
|
@ -23,6 +24,7 @@ public class TicTacToeGame extends JPanel { |
|
|
|
|
|
|
|
|
public TicTacToeGame() { |
|
|
public TicTacToeGame() { |
|
|
this.setSize(width, height); |
|
|
this.setSize(width, height); |
|
|
|
|
|
setBackground(Color.black); |
|
|
setLayout(null); |
|
|
setLayout(null); |
|
|
initField(); |
|
|
initField(); |
|
|
initScoreboard(); |
|
|
initScoreboard(); |
|
@ -68,6 +70,7 @@ public class TicTacToeGame extends JPanel { |
|
|
protected void paintComponent(Graphics g) { |
|
|
protected void paintComponent(Graphics g) { |
|
|
super.paintComponent(g); |
|
|
super.paintComponent(g); |
|
|
Graphics2D g2 = (Graphics2D) g; |
|
|
Graphics2D g2 = (Graphics2D) g; |
|
|
|
|
|
g2.setColor(Color.white); |
|
|
|
|
|
|
|
|
Line2D lin = new Line2D.Float(250, 150, 250, 450); |
|
|
Line2D lin = new Line2D.Float(250, 150, 250, 450); |
|
|
Line2D lin2 = new Line2D.Float(350, 150, 350, 450); |
|
|
Line2D lin2 = new Line2D.Float(350, 150, 350, 450); |
|
@ -85,19 +88,21 @@ 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++; |
|
|
|
|
|
if(turns >= playFieldSize) { |
|
|
|
|
|
JOptionPane.showMessageDialog(getParent(),"Draw!"); |
|
|
|
|
|
scoreboard.addPoint(0); |
|
|
|
|
|
resetGame(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
turns++; |
|
|
|
|
|
if(turns >= playFieldSize) { |
|
|
|
|
|
JOptionPane.showMessageDialog(getParent(),"Draw!"); |
|
|
|
|
|
scoreboard.addPoint(0); |
|
|
|
|
|
resetGame(); |
|
|
|
|
|
|
|
|
playerID++; |
|
|
|
|
|
if(playerID >= maxPlayers) { |
|
|
|
|
|
playerID = 1; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
playerID++; |
|
|
|
|
|
if(playerID >= maxPlayers) { |
|
|
|
|
|
playerID = 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public int checkPlayfield() { |
|
|
public int checkPlayfield() { |
|
|