From a991d260a0d440ac7ffd4b02cc2ea98ff015c9e0 Mon Sep 17 00:00:00 2001 From: Felix Detig Date: Sun, 13 Feb 2022 22:34:53 +0100 Subject: [PATCH] TicTacToeBrett.Gewinner erkennt diagonale Reihen von oben links nach unten rechts --- .../MiniGames/Shared/Models/TicTacToeBrett.cs | 5 +++++ .../MiniGamesTests/TicTacToeBrettTest.cs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs b/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs index 59468c8..4fe20d0 100644 --- a/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs +++ b/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs @@ -100,6 +100,11 @@ namespace MiniGames.Shared.Models } } + if (dreiGleichGefuellt(Felder[0, 0], Felder[1, 1], Felder[2, 2])) + { + return Felder[0, 0]; + } + return LEER; } } diff --git a/BlazorSolution/MiniGamesTests/TicTacToeBrettTest.cs b/BlazorSolution/MiniGamesTests/TicTacToeBrettTest.cs index dcfa40c..9351135 100644 --- a/BlazorSolution/MiniGamesTests/TicTacToeBrettTest.cs +++ b/BlazorSolution/MiniGamesTests/TicTacToeBrettTest.cs @@ -300,5 +300,23 @@ namespace MiniGamesTests // assert Assert.Equal(erwarteterGewinner, erhaltenerGewinner); } + + [Fact] + public void Gewinner_DiagonaleReiheNWzuSO() + { + // arrange + TicTacToeBrett brett = TestBrett( + 5, TicTacToeBrett.LEER, TicTacToeBrett.LEER, + TicTacToeBrett.LEER, 5, TicTacToeBrett.LEER, + TicTacToeBrett.LEER, TicTacToeBrett.LEER, 5 + ); + int erwarteterGewinner = 5; + + // act + int erhaltenerGewinner = brett.Gewinner(); + + // assert + Assert.Equal(erwarteterGewinner, erhaltenerGewinner); + } } }