Browse Source

Refactored TicTacToeBrett.Gewinner

feature/tictactoe
Felix Detig 3 years ago
parent
commit
8e15fb5e7b
  1. 16
      BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs

16
BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs

@ -80,24 +80,24 @@ namespace MiniGames.Shared.Models
return true; return true;
} }
protected bool dreiGleichGefuellt(int a, int b, int c)
{
return a != LEER && a == b && b == c;
}
public int Gewinner() public int Gewinner()
{ {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
if (Felder[i, 0] == Felder[i, 1] && Felder[i, 1] == Felder[i, 2] && Felder[i, 0] != LEER)
if (dreiGleichGefuellt(Felder[i, 0], Felder[i, 1], Felder[i, 2]))
{ {
return Felder[i, 0]; return Felder[i, 0];
} }
}
if (Felder[0, 0] == Felder[1, 0] && Felder[1, 0] == Felder[2, 0] && Felder[0, 0] != LEER)
if (dreiGleichGefuellt(Felder[0, i], Felder[1, i], Felder[2, i]))
{ {
return Felder[0, 0];
return Felder[0, i];
} }
if (Felder[0, 1] == Felder[1, 1] && Felder[1, 1] == Felder[2, 1] && Felder[0, 1] != LEER)
{
return Felder[0, 1];
} }
return LEER; return LEER;

Loading…
Cancel
Save