You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
865 B
49 lines
865 B
package TicTacToe;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
|
|
import javax.swing.JButton;
|
|
|
|
public class cell extends JButton {
|
|
|
|
public int playerID = 0;
|
|
private TicTacToeGame ttt;
|
|
|
|
public cell(TicTacToeGame _ttt) {
|
|
ttt = _ttt;
|
|
setBackground(new Color(255,255,255));
|
|
|
|
addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
OnMouseClick();
|
|
}
|
|
});
|
|
}
|
|
|
|
protected void OnMouseClick() {
|
|
if (playerID == 0) {
|
|
playerID = ttt.playerID;
|
|
ttt.endTurn();
|
|
setEnabled(false);
|
|
|
|
switch (playerID) {
|
|
case 1:
|
|
setBackground(new Color(255, 0, 0));
|
|
break;
|
|
case 2:
|
|
setBackground(new Color(0, 0, 255));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void reset() {
|
|
playerID = 0;
|
|
setEnabled(true);
|
|
setBackground(new Color(255,255,255));
|
|
}
|
|
|
|
}
|