From 8e15fb5e7b6fe1ef14c01ce01cf9d14531816d6a Mon Sep 17 00:00:00 2001 From: Felix Detig Date: Sun, 13 Feb 2022 20:59:31 +0100 Subject: [PATCH] Refactored TicTacToeBrett.Gewinner --- .../MiniGames/Shared/Models/TicTacToeBrett.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs b/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs index 646f1a4..59468c8 100644 --- a/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs +++ b/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs @@ -80,24 +80,24 @@ namespace MiniGames.Shared.Models return true; } + protected bool dreiGleichGefuellt(int a, int b, int c) + { + return a != LEER && a == b && b == c; + } + public int Gewinner() { 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]; } - } - - if (Felder[0, 0] == Felder[1, 0] && Felder[1, 0] == Felder[2, 0] && Felder[0, 0] != LEER) - { - return Felder[0, 0]; - } - if (Felder[0, 1] == Felder[1, 1] && Felder[1, 1] == Felder[2, 1] && Felder[0, 1] != LEER) - { - return Felder[0, 1]; + if (dreiGleichGefuellt(Felder[0, i], Felder[1, i], Felder[2, i])) + { + return Felder[0, i]; + } } return LEER;