From dc33ff66562218b0edd8ea2f77a715f6a678322f Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Mon, 27 May 2024 18:10:24 +0200 Subject: [PATCH] Fixed minor code smell + added swap event to Program.cs --- .../Events/SwapTilesNotifiedEventArgs.cs | 9 +++++---- Qwirkle/QwirkleConsoleApp/NotificationClass.cs | 9 +++++++++ Qwirkle/QwirkleConsoleApp/Program.cs | 4 ++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Events/SwapTilesNotifiedEventArgs.cs b/Qwirkle/QwirkleClassLibrary/Events/SwapTilesNotifiedEventArgs.cs index 8831ee9..c75b65f 100644 --- a/Qwirkle/QwirkleClassLibrary/Events/SwapTilesNotifiedEventArgs.cs +++ b/Qwirkle/QwirkleClassLibrary/Events/SwapTilesNotifiedEventArgs.cs @@ -1,6 +1,7 @@ -namespace QwirkleClassLibrary.Events; - -public class SwapTilesNotifiedEventArgs(string reason) +namespace QwirkleClassLibrary.Events { - public string Reason { get; private set; } = reason; + public class SwapTilesNotifiedEventArgs(string reason) + { + public string? Reason { get; private set; } + } } \ No newline at end of file diff --git a/Qwirkle/QwirkleConsoleApp/NotificationClass.cs b/Qwirkle/QwirkleConsoleApp/NotificationClass.cs index 5c6a130..7542aff 100644 --- a/Qwirkle/QwirkleConsoleApp/NotificationClass.cs +++ b/Qwirkle/QwirkleConsoleApp/NotificationClass.cs @@ -46,5 +46,14 @@ namespace QwirkleConsoleApp ResetColor(); } + + public void NotificationSwapTile(object? sender, SwapTilesNotifiedEventArgs args) + { + ForegroundColor = ConsoleColor.Magenta; + WriteLine(); + WriteLine(args.Reason); + WriteLine(); + ResetColor(); + } } } diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index 82a7639..80e3f59 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -129,6 +129,9 @@ static void AddTile(Game game) static void SwapTile(Game game) { + var nc = new NotificationClass(); + game.SwapTilesNotified += nc.NotificationSwapTile; + var tilesToSwap = new List(); bool continueSwap = true; @@ -161,6 +164,7 @@ static void SwapTile(Game game) } game.SwapTiles(game.GetPlayingPlayer(), tilesToSwap); + game.SwapTilesNotified -= nc.NotificationSwapTile; } static void MenuSwitch(Game game)