Created
July 27, 2019 11:16
-
-
Save BMU-Verlag/206706f946852e9fc6ad1f3f0854d036 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
private bool CheckForWinner() | |
{ | |
// Check rows | |
foreach (List row in fields) | |
{ | |
if (row[0] != Player.None && row[0] == row[1] && row[1] == row[2]) | |
{ | |
return true; | |
} | |
} | |
// Check columns | |
for (var column_index = 0; column_index < FIELD_SIZE; column_index++) | |
{ | |
if (fields[0][column_index] != Player.None | |
&& fields[0][column_index] == fields[1][column_index] | |
&& fields[1][column_index] == fields[2][column_index]) | |
{ | |
return true; | |
} | |
} | |
// Check left-right diagonal | |
if (fields[0][0] != Player.None && fields[0][0] == fields[1][1] | |
&& fields[1][1] == fields[2][2]) | |
{ | |
return true; | |
} | |
// Check right-left diagonal | |
if (fields[0][2] != Player.None && fields[1][1] == fields[2][0] | |
&& fields[1][1] == fields[0][2]) | |
{ | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment