Skip to content
Snippets Groups Projects
Commit 45b5babf authored by Tarek's avatar Tarek
Browse files

Implemented winCheck method

parent 252bda28
No related branches found
No related tags found
1 merge request!6- Created the GUI for the game
......@@ -8,7 +8,7 @@ public class GameBoard {
void gameBoard(){
public void gameBoard(){
}
......@@ -40,10 +40,30 @@ public class GameBoard {
* @return Winner or tie or unfinished
*/
public int winCheck(){
// game isn't finished
for (int i = 0; i < 9; i++) {
int x = i % 3 + 1;
int y = i / 3;
if (board[y][x] == 0)
return 0;
}
for (int i = 0; i < 3; i++){
// vertical
if (board[0][i] == board[1][i] && board[1][i] == board[2][i])
return board[0][i];
// horizontal
if (board[i][0] == board[i][1] && board[i][1] == board[i][2])
return board[i][0];
}
// diagonal
if (board[0][0] == board[1][1] && board[1][1] == board[2][2])
return board[1][1];
if (board[2][0] == board[1][1] && board[1][1] == board[0][2])
return board[1][1];
return 0;
// Tie
return 3;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment