From 39ad4eadcdcb82452f92ec41a3a73045464c92df Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Wed, 28 Sep 2022 19:22:58 +0200 Subject: [PATCH 1/3] :alembic: Bang out a quick and dirty console prototype --- Sources/App/Program.cs | 273 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 269 insertions(+), 4 deletions(-) diff --git a/Sources/App/Program.cs b/Sources/App/Program.cs index 521fa48..a077909 100644 --- a/Sources/App/Program.cs +++ b/Sources/App/Program.cs @@ -1,6 +1,11 @@ using Data; +using Model.Dice; +using Model.Dice.Faces; using Model.Games; -using System.Diagnostics; +using Model.Players; +using System; +using System.Collections.Generic; +using System.Linq; namespace App { @@ -9,8 +14,268 @@ namespace App static void Main(string[] args) { ILoader loader = new Stub(); - GameRunner gameRunner = loader.LoadApp(); - // use gameRunner to play + GameRunner gameRunner; + try + { + gameRunner = loader.LoadApp(); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + Console.WriteLine(ex.StackTrace); + gameRunner = new(new PlayerManager(), new DieManager(), null); + } + + string menuChoice = "nothing"; + + while (menuChoice != "q") + { + Console.WriteLine( + "l... load a game\n" + + "n... start new game\n" + + "d... delete a game\n" + + "c... create a group of dice\n" + + "q... QUIT\n" + + ">" + ); + + menuChoice = Console.ReadLine(); + + switch (menuChoice) + { + case "q": + break; + + case "l": + string loadName = ChooseGame(gameRunner); + if (gameRunner.GetOneGameByName(loadName) != null) + { + Play(gameRunner, loadName); + } + break; + + case "n": + + if (!gameRunner.GetGlobalDiceGroups().Any()) + { + Console.WriteLine("make at least one dice group first, then try again"); + break; + } + IEnumerable> newGameDice = PrepareDice(gameRunner); + + string newGameName; + Console.WriteLine("give this new game a name\n>"); + newGameName = Console.ReadLine(); + PlayerManager playerManager = PreparePlayers(gameRunner); + + gameRunner.StartNewGame(newGameName, playerManager, newGameDice); + Play(gameRunner, newGameName); + + break; + + case "d": + string deleteName = ChooseGame(gameRunner); + gameRunner.DeleteGame(gameRunner.GetOneGameByName(deleteName)); + break; + + case "c": + string newGroupName; + Console.WriteLine("give this new dice group a name"); + newGroupName = Console.ReadLine(); + + List> newGroupDice = new(); + string menuChoiceNewDice = ""; + while (!(menuChoiceNewDice.Equals("ok") && newGroupDice.Any())) + { + AbstractDie die = null; + Console.WriteLine("create a die you want to add (at least one), or enter 'ok' if you're finished"); + Console.WriteLine("what type of die ?\n" + + "n... number\n" + + "c... color\n" + + "i... image"); + menuChoiceNewDice = Console.ReadLine(); + switch (menuChoiceNewDice) + { + case "n": + die = MakeNumberDie(); + break; + + case "c": + die = MakeColorDie(); + break; + + case "i": + die = MakeImageDie(); + break; + } + // almost no checks, this is temporary + if (die is not null) + { + newGroupDice.Add(die); + } + } + gameRunner.AddGlobalDiceGroup(newGroupName, newGroupDice); + break; + + default: + Console.WriteLine("u wot m8?"); + break; + } + } + + } + + private static void Play(GameRunner gameRunner, string name) + { + string menuChoicePlay = ""; + while (menuChoicePlay != "q") + { + Game game = gameRunner.GetOneGameByName(name); + Console.WriteLine($"{game.GetWhoPlaysNow()}'s turn\n" + + "q... quit\n" + + "h... show history\n" + + "any other... throw"); + menuChoicePlay = Console.ReadLine(); + switch (menuChoicePlay) + { + case "q": + break; + case "h": + foreach (Turn turn in game.GetHistory()) + { + Console.WriteLine(turn); + } + break; + default: + GameRunner.PlayGame(game); + Console.WriteLine(game.GetHistory().Last()); + break; + } + } + } + + private static string ChooseGame(GameRunner gameRunner) + { + string name; + Console.WriteLine("which of these games?\n>"); + foreach (Game game in gameRunner.GetAllGames()) + { + Console.WriteLine(game); + } + name = Console.ReadLine(); + return name; + } + + private static NumberDie MakeNumberDie() + { + NumberDie die; + List faces = new(); + string menuChoiceNewFaces = ""; + + while (menuChoiceNewFaces != "ok") + { + Console.WriteLine("create a face with a number, or enter 'ok' if you're finished"); + menuChoiceNewFaces = Console.ReadLine(); + + if (!menuChoiceNewFaces.Equals("ok") && int.TryParse(menuChoiceNewFaces, out int num)) + { + faces.Add(new(num)); + } + } + + die = new NumberDie(faces.ToArray()); + return die; + } + + private static ColorDie MakeColorDie() + { + ColorDie die; + List faces = new(); + string menuChoiceNewFaces = ""; + + while (!menuChoiceNewFaces.Equals("ok")) + { + Console.WriteLine("create a face with an color hex code, or enter 'ok' if you're finished"); + menuChoiceNewFaces = Console.ReadLine(); + if (menuChoiceNewFaces != "ok") faces.Add(new(menuChoiceNewFaces)); + } + + die = new ColorDie(faces.ToArray()); + return die; + } + + private static ImageDie MakeImageDie() + { + ImageDie die; + List faces = new(); + string menuChoiceNewFaces = ""; + + while (!menuChoiceNewFaces.Equals("ok")) + { + Console.WriteLine("create a face with an image url, or enter 'ok' if you're finished"); + menuChoiceNewFaces = Console.ReadLine(); + + if (menuChoiceNewFaces != "ok") faces.Add(new(menuChoiceNewFaces)); + } + + die = new ImageDie(faces.ToArray()); + return die; + } + + private static IEnumerable> PrepareDice(GameRunner gameRunner) + { + List> result = new(); + Console.WriteLine("add dice to the game"); + Console.WriteLine("all known dice or groups of dice:"); + foreach ((string name, IEnumerable> dice) in gameRunner.GetGlobalDiceGroups()) + { + Console.WriteLine($"{name} -- {dice}"); + } + string menuChoiceDice = ""; + while (!(menuChoiceDice.Equals("ok") && result.Any())) + { + Console.WriteLine("write the name of a dice group you want to add (at least one), or 'ok' if you're finished"); + menuChoiceDice = Console.ReadLine(); + // no checks, this is temporary + if (!menuChoiceDice.Equals("ok")) + { + IEnumerable> chosenDice = gameRunner.GetOneGlobalDiceGroupByName(menuChoiceDice).Value; + foreach (AbstractDie die in chosenDice) + { + result.Add(die); + } + } + } + return result.AsEnumerable(); + } + private static PlayerManager PreparePlayers(GameRunner gameRunner) + { + PlayerManager result = new(); + Console.WriteLine("add players to the game"); + Console.WriteLine("all known players:"); + foreach (Player player in gameRunner.GetGlobalPlayers()) + { + Console.WriteLine(player); + } + string menuChoicePlayers = ""; + while (!(menuChoicePlayers.Equals("ok") && result.GetAll().Any())) + { + Console.WriteLine("write the name of a player you want to add (at least one), or 'ok' if you're finished"); + menuChoicePlayers = Console.ReadLine(); + if (!menuChoicePlayers.Equals("ok")) + { + Player player = new(menuChoicePlayers); + if (!gameRunner.GetGlobalPlayers().Contains(player)) + { + // if the player didn't exist, now it does... this is temporary + gameRunner.AddGlobalPlayer(player); + } + // almost no checks, this is temporary + result.Add(player); + } + } + + return result; } } -} +} \ No newline at end of file -- 2.36.3 From e0abed25903714bbea8e47ad4da4731ab4f698bd Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Wed, 28 Sep 2022 19:23:27 +0200 Subject: [PATCH 2/3] :fire: Remove ption to use shorter hexcodes for colors --- Sources/Model/Dice/Faces/ColorDieFace.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Sources/Model/Dice/Faces/ColorDieFace.cs b/Sources/Model/Dice/Faces/ColorDieFace.cs index fc7f7a0..77b5d3c 100644 --- a/Sources/Model/Dice/Faces/ColorDieFace.cs +++ b/Sources/Model/Dice/Faces/ColorDieFace.cs @@ -22,15 +22,6 @@ namespace Model.Dice.Faces hexValueString = hexValueString[1..]; } - // if style is "f0b", this constructor can develop it to "ff00bb" before doing the job - if (hexValueString.Length == 3) - { - foreach (char ch in hexValueString) - { - // replace one instance of the char by two instances of it - hexValueString = hexValueString.Replace(new string(ch, 1), new string(ch, 2)); - } - } int result = int.Parse(hexValueString, System.Globalization.NumberStyles.HexNumber); if (result < 0) Value = 0; -- 2.36.3 From 796c599f3f1d5e422783826e5f1d5cfebd1a46e7 Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Wed, 28 Sep 2022 19:36:37 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9E=96=F0=9F=92=9A=20Remove=20console=20?= =?UTF-8?q?prototype=20from=20the=20CI=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you want to launch the console app, you need to load the DiceAppConsole "solution" --- Sources/DiceApp.sln | 9 ------- Sources/DiceAppConsole.sln | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 Sources/DiceAppConsole.sln diff --git a/Sources/DiceApp.sln b/Sources/DiceApp.sln index a6b9d77..7545479 100644 --- a/Sources/DiceApp.sln +++ b/Sources/DiceApp.sln @@ -5,11 +5,6 @@ VisualStudioVersion = 17.3.32901.215 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App", "App\App.csproj", "{81443A61-4C32-4863-90B5-7548C7385059}" - ProjectSection(ProjectDependencies) = postProject - {4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6} = {4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6} - EndProjectSection -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{11BDDDA8-CBED-46EE-A224-144C3CD545A7}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "Data\Data.csproj", "{3047BFD8-EF44-4095-9E54-45D47C7AB212}" @@ -26,10 +21,6 @@ Global {4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6}.Debug|Any CPU.Build.0 = Debug|Any CPU {4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6}.Release|Any CPU.ActiveCfg = Release|Any CPU {4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6}.Release|Any CPU.Build.0 = Release|Any CPU - {81443A61-4C32-4863-90B5-7548C7385059}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {81443A61-4C32-4863-90B5-7548C7385059}.Debug|Any CPU.Build.0 = Debug|Any CPU - {81443A61-4C32-4863-90B5-7548C7385059}.Release|Any CPU.ActiveCfg = Release|Any CPU - {81443A61-4C32-4863-90B5-7548C7385059}.Release|Any CPU.Build.0 = Release|Any CPU {11BDDDA8-CBED-46EE-A224-144C3CD545A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {11BDDDA8-CBED-46EE-A224-144C3CD545A7}.Debug|Any CPU.Build.0 = Debug|Any CPU {11BDDDA8-CBED-46EE-A224-144C3CD545A7}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Sources/DiceAppConsole.sln b/Sources/DiceAppConsole.sln new file mode 100644 index 0000000..a6b9d77 --- /dev/null +++ b/Sources/DiceAppConsole.sln @@ -0,0 +1,48 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32901.215 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App", "App\App.csproj", "{81443A61-4C32-4863-90B5-7548C7385059}" + ProjectSection(ProjectDependencies) = postProject + {4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6} = {4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6} + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{11BDDDA8-CBED-46EE-A224-144C3CD545A7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "Data\Data.csproj", "{3047BFD8-EF44-4095-9E54-45D47C7AB212}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{953D2D67-BCE7-412C-B7BB-7C63B5592359}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F3B0337-8019-4988-ADFE-FD7AE5BCDBF6}.Release|Any CPU.Build.0 = Release|Any CPU + {81443A61-4C32-4863-90B5-7548C7385059}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {81443A61-4C32-4863-90B5-7548C7385059}.Debug|Any CPU.Build.0 = Debug|Any CPU + {81443A61-4C32-4863-90B5-7548C7385059}.Release|Any CPU.ActiveCfg = Release|Any CPU + {81443A61-4C32-4863-90B5-7548C7385059}.Release|Any CPU.Build.0 = Release|Any CPU + {11BDDDA8-CBED-46EE-A224-144C3CD545A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {11BDDDA8-CBED-46EE-A224-144C3CD545A7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {11BDDDA8-CBED-46EE-A224-144C3CD545A7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {11BDDDA8-CBED-46EE-A224-144C3CD545A7}.Release|Any CPU.Build.0 = Release|Any CPU + {3047BFD8-EF44-4095-9E54-45D47C7AB212}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3047BFD8-EF44-4095-9E54-45D47C7AB212}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3047BFD8-EF44-4095-9E54-45D47C7AB212}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3047BFD8-EF44-4095-9E54-45D47C7AB212}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F1DFFC48-0814-4BD5-A8E6-9F757CEB8725} + EndGlobalSection +EndGlobal -- 2.36.3