Merge pull request '⚗️ bang-out-dirty-prototype' (#91) from bang-out-dirty-prototype into main
continuous-integration/drone/push Build is passing Details

Reviewed-on: #91
pull/92/head
Alexis Drai 3 years ago
commit 42a106c9b5

@ -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<AbstractDie<AbstractDieFace>> 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<AbstractDie<AbstractDieFace>> newGroupDice = new();
string menuChoiceNewDice = "";
while (!(menuChoiceNewDice.Equals("ok") && newGroupDice.Any()))
{
AbstractDie<AbstractDieFace> 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<NumberDieFace> 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<ColorDieFace> 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<ImageDieFace> 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<AbstractDie<AbstractDieFace>> PrepareDice(GameRunner gameRunner)
{
List<AbstractDie<AbstractDieFace>> result = new();
Console.WriteLine("add dice to the game");
Console.WriteLine("all known dice or groups of dice:");
foreach ((string name, IEnumerable<AbstractDie<AbstractDieFace>> 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<AbstractDie<AbstractDieFace>> chosenDice = gameRunner.GetOneGlobalDiceGroupByName(menuChoiceDice).Value;
foreach (AbstractDie<AbstractDieFace> 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;
}
}
}

@ -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

@ -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

@ -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;

Loading…
Cancel
Save