|
@ -1,4 +1,5 @@ |
|
|
package TicTacToe; |
|
|
package TicTacToe; |
|
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
import java.awt.Color; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.ActionListener; |
|
|
import java.awt.event.ActionListener; |
|
@ -9,10 +10,11 @@ public class cell extends JButton { |
|
|
|
|
|
|
|
|
public int playerID = 0; |
|
|
public int playerID = 0; |
|
|
private TicTacToeGame ttt; |
|
|
private TicTacToeGame ttt; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public cell(TicTacToeGame _ttt) { |
|
|
public cell(TicTacToeGame _ttt) { |
|
|
ttt = _ttt; |
|
|
ttt = _ttt; |
|
|
|
|
|
|
|
|
|
|
|
setBackground(new Color(255,255,255)); |
|
|
|
|
|
|
|
|
addActionListener(new ActionListener() { |
|
|
addActionListener(new ActionListener() { |
|
|
@Override |
|
|
@Override |
|
|
public void actionPerformed(ActionEvent e) { |
|
|
public void actionPerformed(ActionEvent e) { |
|
@ -22,23 +24,26 @@ public class cell extends JButton { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected void OnMouseClick() { |
|
|
protected void OnMouseClick() { |
|
|
if(playerID == 0) { |
|
|
|
|
|
playerID = ttt.playerID; |
|
|
|
|
|
|
|
|
if (playerID == 0) { |
|
|
|
|
|
playerID = ttt.playerID; |
|
|
ttt.endTurn(); |
|
|
ttt.endTurn(); |
|
|
setEnabled(false); |
|
|
setEnabled(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (playerID) { |
|
|
switch (playerID) { |
|
|
case 1: setBackground(new Color(255,0,0)); |
|
|
|
|
|
break; |
|
|
|
|
|
case 2: setBackground(new Color(0,0,255)); |
|
|
|
|
|
break; |
|
|
|
|
|
default: ; |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
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)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |