-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameChecker.java
More file actions
38 lines (33 loc) · 968 Bytes
/
GameChecker.java
File metadata and controls
38 lines (33 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class GameChecker {
private Board board;
public GameChecker(Board board){
this.board = board;
}
public boolean haveYouWon (char move){
for (int i = 0; i < board.getBoardSize(); i++) {
if(board.isColumn(move, i))
return true;
if(board.isRow(move,i))
return true;
}
if (board.isDiagonal(move) || board.isAntiDiagonal(move))
return true;
return false;
}
public boolean checkWinner(){
if (haveYouWon( 'X')) {
board.printBoard();
System.out.println("You win!");
return true;
}
if (haveYouWon('O')) {
board.printBoard();
System.out.println("Computer wins!");
return true;
}
if(!board.isFinished()) return false; //******
board.printBoard();
System.out.println("You tie.");
return true;
}
}