From 2aaac393b75774495bfc6638999513c5587ac4bf Mon Sep 17 00:00:00 2001 From: Felix Detig Date: Fri, 11 Feb 2022 23:10:39 +0100 Subject: [PATCH] =?UTF-8?q?TicTacToeBrett.Set=20auf=20ein=20belegtes=20Fel?= =?UTF-8?q?d=20l=C3=A4sst=20das=20Feld=20unver=C3=A4ndert=20und=20gibt=20f?= =?UTF-8?q?alse=20zur=C3=BCck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MiniGames/Shared/Models/TicTacToeBrett.cs | 8 +++++++- .../MiniGamesTests/TicTacToeBrettTest.cs | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs b/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs index 329bb08..460e7f2 100644 --- a/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs +++ b/BlazorSolution/MiniGames/Shared/Models/TicTacToeBrett.cs @@ -43,7 +43,13 @@ namespace MiniGames.Shared.Models public bool Set(int pos, int wert) { - Felder[pos / 3, pos % 3] = wert; + int x = pos / 3; + int y = pos % 3; + + if (Felder[x, y] != -1) + return false; + + Felder[x, y] = wert; return true; } diff --git a/BlazorSolution/MiniGamesTests/TicTacToeBrettTest.cs b/BlazorSolution/MiniGamesTests/TicTacToeBrettTest.cs index 53a56f8..ac787a9 100644 --- a/BlazorSolution/MiniGamesTests/TicTacToeBrettTest.cs +++ b/BlazorSolution/MiniGamesTests/TicTacToeBrettTest.cs @@ -44,6 +44,24 @@ namespace MiniGamesTests Assert.True(brett.Gleich(erwartetesBrett)); } + [Fact] + public void Set_BelegtesFeldBelegenTest() + { + // arrange + TicTacToeBrett brett = TestBrett(1); + TicTacToeBrett erwartetesBrett = TestBrett(1); + int pos = 0; + int wert = 1; + bool erwartetGesetzt = false; + + // act + bool erhaltenGesetzt = brett.Set(pos, wert); + + // assert + Assert.Equal(erwartetGesetzt, erhaltenGesetzt); + Assert.True(brett.Gleich(erwartetesBrett)); + } + [Fact] public void Gleich_LeereBretterGleichTest() {