add winner function to board.
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
package edu.tictactoe;
|
package edu.tictactoe;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
@@ -11,7 +8,6 @@ import javax.swing.Icon;
|
|||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@@ -83,7 +79,7 @@ public final class Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean winnerCheck() {
|
protected boolean winnerCheck() {
|
||||||
HashSet<BoardButton> checks = new HashSet<BoardButton>(9);
|
|
||||||
if ((buttons[0].played && buttons[4].played && buttons[8].played)
|
if ((buttons[0].played && buttons[4].played && buttons[8].played)
|
||||||
&&
|
&&
|
||||||
buttons[0].player == buttons[4].player
|
buttons[0].player == buttons[4].player
|
||||||
@@ -101,6 +97,51 @@ public final class Board {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((buttons[0].played && buttons[1].played && buttons[2].played)
|
||||||
|
&&
|
||||||
|
buttons[0].player == buttons[1].player
|
||||||
|
&& buttons[1].player == buttons[2].player) {
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((buttons[3].played && buttons[4].played && buttons[5].played)
|
||||||
|
&&
|
||||||
|
buttons[3].player == buttons[4].player
|
||||||
|
&& buttons[4].player == buttons[5].player) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((buttons[6].played && buttons[7].played && buttons[8].played)
|
||||||
|
&&
|
||||||
|
buttons[6].player == buttons[7].player
|
||||||
|
&& buttons[7].player == buttons[8].player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((buttons[0].played && buttons[3].played && buttons[6].played)
|
||||||
|
&&
|
||||||
|
buttons[0].player == buttons[3].player
|
||||||
|
&& buttons[3].player == buttons[6].player) {
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((buttons[1].played && buttons[4].played && buttons[7].played)
|
||||||
|
&&
|
||||||
|
buttons[1].player == buttons[4].player
|
||||||
|
&& buttons[4].player == buttons[7].player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((buttons[2].played && buttons[5].played && buttons[8].played)
|
||||||
|
&&
|
||||||
|
buttons[2].player == buttons[5].player
|
||||||
|
&& buttons[5].player == buttons[8].player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user