|
|
@ -1,6 +1,8 @@ |
|
|
|
package TicTacToe; |
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Graphics; |
|
|
|
import java.awt.Graphics2D; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
|
@ -13,7 +15,7 @@ public class Cell extends JButton { |
|
|
|
|
|
|
|
public Cell(TicTacToeGame _ttt) { |
|
|
|
ttt = _ttt; |
|
|
|
setBackground(new Color(255,255,255)); |
|
|
|
setBackground(new Color(255, 255, 255)); |
|
|
|
|
|
|
|
addActionListener(new ActionListener() { |
|
|
|
@Override |
|
|
@ -28,22 +30,31 @@ public class Cell extends JButton { |
|
|
|
playerID = ttt.playerID; |
|
|
|
ttt.endTurn(); |
|
|
|
setEnabled(false); |
|
|
|
repaint(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
switch (playerID) { |
|
|
|
case 1: |
|
|
|
setBackground(new Color(255, 0, 0)); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
setBackground(new Color(0, 0, 255)); |
|
|
|
break; |
|
|
|
} |
|
|
|
@Override |
|
|
|
protected void paintComponent(Graphics g) { |
|
|
|
super.paintComponent(g); |
|
|
|
Graphics2D g2 = (Graphics2D) g; |
|
|
|
|
|
|
|
switch (playerID) { |
|
|
|
case 1: |
|
|
|
g2.drawOval(5, 5, 90, 90); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
g2.drawLine(5, 5, 90, 90); |
|
|
|
g2.drawLine(90, 5, 5, 90); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void reset() { |
|
|
|
playerID = 0; |
|
|
|
setEnabled(true); |
|
|
|
setBackground(new Color(255,255,255)); |
|
|
|
repaint(); |
|
|
|
} |
|
|
|
|
|
|
|
} |