Last active
March 9, 2019 20:14
-
-
Save gunharth/728678ccb3a6d60757720e92e87a1aa2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String checkWinner() { | |
int index = 0; | |
for(int i = 0; i < 3; i++) { | |
if(!game[index].equals("") && | |
game[index].equals(game[index+1]) && | |
game[index].equals(game[index+2])) { | |
return game[index]; | |
} | |
index += 3; | |
} | |
index = 0; | |
for(int i = 0; i < 3; i++) { | |
if(!game[index].equals("") && | |
game[index].equals(game[index+3]) && | |
game[index].equals(game[index+6])) { | |
return game[index]; | |
} | |
index++; | |
} | |
if(!game[0].equals("") && game[0].equals(game[4]) && game[0].equals(game[8])) { | |
return game[0]; | |
} | |
if(!game[2].equals("") && game[2].equals(game[4]) && game[2].equals(game[6])) { | |
return game[2]; | |
} | |
return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment