From 113f7bb56142fb1f89d10165b56748429f7a83e4 Mon Sep 17 00:00:00 2001 From: Christian Kauer Date: Fri, 22 Dec 2023 22:05:36 +0100 Subject: [PATCH] dev --- GameContract/IGameHandler.cs | 13 ++++ GameHandler.UnitTests/GameServiceTests.cs | 2 +- .../DeathGameHandler.cs | 10 ++- GameHandler/GameHandler/FreeGameHandler.cs | 17 +++++ GameHandler/GameService.cs | 36 ++++++++-- GameModel/FreeGame/FreeGameModel.cs | 12 ++++ KoogleCli/Program.cs | 71 ++++++++++++++----- 7 files changed, 135 insertions(+), 26 deletions(-) create mode 100644 GameContract/IGameHandler.cs rename GameHandler/{DeathGame => GameHandler}/DeathGameHandler.cs (96%) create mode 100644 GameHandler/GameHandler/FreeGameHandler.cs create mode 100644 GameModel/FreeGame/FreeGameModel.cs diff --git a/GameContract/IGameHandler.cs b/GameContract/IGameHandler.cs new file mode 100644 index 0000000..78a351c --- /dev/null +++ b/GameContract/IGameHandler.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GameContract +{ + public interface IGameHandler + { + static string GetGameName() => "Default Hello from interface"; + } +} diff --git a/GameHandler.UnitTests/GameServiceTests.cs b/GameHandler.UnitTests/GameServiceTests.cs index 10b80ad..de72819 100644 --- a/GameHandler.UnitTests/GameServiceTests.cs +++ b/GameHandler.UnitTests/GameServiceTests.cs @@ -47,7 +47,7 @@ namespace GameHandler.UnitTests public void HandleThrow_UpdateTheBoardState() { GameService service = new GameService(); - var ts1 = service.Start(); + var ts1 = service.Start(1); var bs1 = ts1.BoardState; var pinThrow = PinThrow.Create(1,PinPicture.Create(1,PinState.Down), false, false); diff --git a/GameHandler/DeathGame/DeathGameHandler.cs b/GameHandler/GameHandler/DeathGameHandler.cs similarity index 96% rename from GameHandler/DeathGame/DeathGameHandler.cs rename to GameHandler/GameHandler/DeathGameHandler.cs index d2772bc..77048e4 100644 --- a/GameHandler/DeathGame/DeathGameHandler.cs +++ b/GameHandler/GameHandler/DeathGameHandler.cs @@ -1,4 +1,5 @@ -using GameModel; +using GameContract; +using GameModel; using GameModel.DeathGame; using System; using System.Collections.Generic; @@ -11,7 +12,7 @@ namespace GameHandler.DeathGame public delegate void CoffinCompleted(Coffin coffin); public delegate void FirstThrowFailed(Coffin coffin); - public class DeathGameHandler + public class DeathGameHandler : IGameHandler { const int MIN_PLAYER_COUNT = 3; const int MAX_PLAYER_COUNT = 12; @@ -176,5 +177,10 @@ namespace GameHandler.DeathGame return result; } + + public static string GetGameName() + { + return "Totenkiste"; + } } } diff --git a/GameHandler/GameHandler/FreeGameHandler.cs b/GameHandler/GameHandler/FreeGameHandler.cs new file mode 100644 index 0000000..8c63100 --- /dev/null +++ b/GameHandler/GameHandler/FreeGameHandler.cs @@ -0,0 +1,17 @@ +using GameContract; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GameHandler.GameHandler +{ + public class FreeGameHandler : IGameHandler + { + public static string GetGameName() + { + return "Freies Spiel"; + } + } +} diff --git a/GameHandler/GameService.cs b/GameHandler/GameService.cs index 1e19d8c..6b62be9 100644 --- a/GameHandler/GameService.cs +++ b/GameHandler/GameService.cs @@ -1,8 +1,10 @@ -using GameModel; +using GameContract; +using GameModel; using GameModel.Exceptions; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -16,11 +18,16 @@ namespace GameHandler private ThrowHandler _th; private ThrowState _lastState; + public GameService() + { + LoadGameHandler(); + } + public string ThrowModeName { get { - if (_lastState != null) + if (_lastState != null) { return _lastState.BoardState.ThrowMode == ThrowMode.Decrease ? "Abräumen" : "Volle"; } @@ -28,12 +35,12 @@ namespace GameHandler } } - public ThrowState Start(int GameTypeId=0) + public ThrowState Start(string gameName) // TODO: add players { if (_isStarted) { throw new InvalidGameStateExcpetion("Game already started"); - } + } if (!_isStarted) { _isStarted = true; @@ -48,7 +55,7 @@ namespace GameHandler return _lastState; } - public ThrowState HandleThrow(PinThrow pinThrow) + public ThrowState HandleThrow(PinThrow pinThrow) { if (!_isStarted) { @@ -67,5 +74,24 @@ namespace GameHandler } _isStarted = false; } + + public static Dictionary LoadGameHandler() + { + var res = new Dictionary(); + var type = typeof(IGameHandler); + var types = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(s => s.GetTypes()) + .Where(p => type.IsAssignableFrom(p) && (!p.IsInterface)); + + foreach (var item in types) + { + MethodInfo staticMethodInfo = item.GetMethod("GetGameName"); + string returnValue = Convert.ToString(staticMethodInfo.Invoke(null, new object[] { })); + + res.Add(returnValue, item); + } + + return res; + } } } diff --git a/GameModel/FreeGame/FreeGameModel.cs b/GameModel/FreeGame/FreeGameModel.cs new file mode 100644 index 0000000..fa0eab6 --- /dev/null +++ b/GameModel/FreeGame/FreeGameModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GameModel.FreeGame +{ + public record FreeGameModel + { + } +} diff --git a/KoogleCli/Program.cs b/KoogleCli/Program.cs index df78e0e..9694134 100644 --- a/KoogleCli/Program.cs +++ b/KoogleCli/Program.cs @@ -8,26 +8,29 @@ using Spectre.Console; using static System.Runtime.InteropServices.JavaScript.JSType; AnsiConsole.MarkupLine("Welcome to [green]koogle[/]"); - -do +ShowMainMenu(); +void ShowMainMenu() { - var option = AnsiConsole.Prompt( - new SelectionPrompt