♻️ Rename GameRunner to MasterOfCeremonies
continuous-integration/drone/push Build is passing Details

pull/125/head
Alexis Drai 3 years ago
parent 08c1e415a9
commit b21b78135e

@ -19,16 +19,16 @@ namespace App
{ {
// MODEL stuff // MODEL stuff
ILoader loader = new Stub(); ILoader loader = new Stub();
GameRunner gameRunner; MasterOfCeremonies masterOfCeremonies;
try try
{ {
gameRunner = loader.LoadApp(); masterOfCeremonies = loader.LoadApp();
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.StackTrace);
gameRunner = new(new PlayerManager(), new DieManager(), null); masterOfCeremonies = new(new PlayerManager(), new DieManager(), null);
} }
try try
@ -48,7 +48,7 @@ namespace App
try try
{ {
// persist them as models ! // persist them as models !
gameRunner.GlobalPlayerManager.Add(entity.ToModel()); masterOfCeremonies.GlobalPlayerManager.Add(entity.ToModel());
Debug.WriteLine($"{entity.ID} -- {entity.Name}"); Debug.WriteLine($"{entity.ID} -- {entity.Name}");
} }
catch (Exception ex) { Debug.WriteLine($"{ex.Message}\n... Never mind"); } catch (Exception ex) { Debug.WriteLine($"{ex.Message}\n... Never mind"); }
@ -81,38 +81,38 @@ namespace App
break; break;
case "l": case "l":
string loadName = ChooseGame(gameRunner); string loadName = ChooseGame(masterOfCeremonies);
if (gameRunner.GameManager.GetOneByName(loadName) != null) if (masterOfCeremonies.GameManager.GetOneByName(loadName) != null)
{ {
Play(gameRunner, loadName); Play(masterOfCeremonies, loadName);
} }
break; break;
case "n": case "n":
if (!gameRunner.DieGroupManager.GetAll().Any()) if (!masterOfCeremonies.DieGroupManager.GetAll().Any())
{ {
Console.WriteLine("make at least one dice group first, then try again"); Console.WriteLine("make at least one dice group first, then try again");
break; break;
} }
Console.WriteLine("add dice to the game"); Console.WriteLine("add dice to the game");
IEnumerable<Die> newGameDice = PrepareDice(gameRunner); IEnumerable<Die> newGameDice = PrepareDice(masterOfCeremonies);
string newGameName; string newGameName;
Console.WriteLine("give this new game a name\n>"); Console.WriteLine("give this new game a name\n>");
newGameName = Console.ReadLine(); newGameName = Console.ReadLine();
Console.WriteLine("add players to the game"); Console.WriteLine("add players to the game");
PlayerManager playerManager = PreparePlayers(gameRunner); PlayerManager playerManager = PreparePlayers(masterOfCeremonies);
gameRunner.StartNewGame(newGameName, playerManager, newGameDice); masterOfCeremonies.StartNewGame(newGameName, playerManager, newGameDice);
Play(gameRunner, newGameName); Play(masterOfCeremonies, newGameName);
break; break;
case "d": case "d":
string deleteName = ChooseGame(gameRunner); string deleteName = ChooseGame(masterOfCeremonies);
gameRunner.GameManager.Remove(gameRunner.GameManager.GetOneByName(deleteName)); masterOfCeremonies.GameManager.Remove(masterOfCeremonies.GameManager.GetOneByName(deleteName));
break; break;
case "c": case "c":
@ -151,19 +151,19 @@ namespace App
newGroupDice.Add(die); newGroupDice.Add(die);
} }
} }
gameRunner.DieGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(newGroupName, newGroupDice)); masterOfCeremonies.DieGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(newGroupName, newGroupDice));
break; break;
case "p": case "p":
ShowPlayers(gameRunner); ShowPlayers(masterOfCeremonies);
break; break;
case "i": case "i":
ShowDice(gameRunner); ShowDice(masterOfCeremonies);
break; break;
case "y": case "y":
PreparePlayers(gameRunner); PreparePlayers(masterOfCeremonies);
break; break;
default: default:
@ -178,7 +178,7 @@ namespace App
using (DiceAppDbContext db = new()) using (DiceAppDbContext db = new())
{ {
// get all the players from the app's memory // get all the players from the app's memory
IEnumerable<Player> models = gameRunner.GlobalPlayerManager.GetAll(); IEnumerable<Player> models = masterOfCeremonies.GlobalPlayerManager.GetAll();
// create a PlayerDbManager (and inject it with the DB) // create a PlayerDbManager (and inject it with the DB)
PlayerDbManager playerDbManager = new(db); PlayerDbManager playerDbManager = new(db);
@ -201,12 +201,12 @@ namespace App
catch (Exception ex) { Debug.WriteLine($"{ex.Message}\n... Couldn't use the database"); } catch (Exception ex) { Debug.WriteLine($"{ex.Message}\n... Couldn't use the database"); }
} }
private static void Play(GameRunner gameRunner, string name) private static void Play(MasterOfCeremonies masterOfCeremonies, string name)
{ {
string menuChoicePlay = ""; string menuChoicePlay = "";
while (menuChoicePlay != "q") while (menuChoicePlay != "q")
{ {
Game game = gameRunner.GameManager.GetOneByName(name); Game game = masterOfCeremonies.GameManager.GetOneByName(name);
Console.WriteLine($"{game.GetWhoPlaysNow()}'s turn\n" + Console.WriteLine($"{game.GetWhoPlaysNow()}'s turn\n" +
"q... quit\n" + "q... quit\n" +
"h... show history\n" + "h... show history\n" +
@ -224,21 +224,21 @@ namespace App
} }
break; break;
case "s": case "s":
gameRunner.GameManager.Add(game); masterOfCeremonies.GameManager.Add(game);
break; break;
default: default:
GameRunner.PlayGame(game); MasterOfCeremonies.PlayGame(game);
Console.WriteLine(game.GetHistory().Last()); Console.WriteLine(game.GetHistory().Last());
break; break;
} }
} }
} }
private static string ChooseGame(GameRunner gameRunner) private static string ChooseGame(MasterOfCeremonies masterOfCeremonies)
{ {
string name; string name;
Console.WriteLine("which of these games?\n(choose by name)\n>"); Console.WriteLine("which of these games?\n(choose by name)\n>");
foreach (Game game in gameRunner.GameManager.GetAll()) foreach (Game game in masterOfCeremonies.GameManager.GetAll())
{ {
Console.WriteLine(game); Console.WriteLine(game);
} }
@ -246,18 +246,18 @@ namespace App
return name; return name;
} }
private static void ShowPlayers(GameRunner gameRunner) private static void ShowPlayers(MasterOfCeremonies masterOfCeremonies)
{ {
Console.WriteLine("Look at all them players!"); Console.WriteLine("Look at all them players!");
foreach (Player player in gameRunner.GlobalPlayerManager.GetAll()) foreach (Player player in masterOfCeremonies.GlobalPlayerManager.GetAll())
{ {
Console.WriteLine(player); Console.WriteLine(player);
} }
} }
private static void ShowDice(GameRunner gameRunner) private static void ShowDice(MasterOfCeremonies masterOfCeremonies)
{ {
foreach ((string name, IEnumerable<Die> dice) in gameRunner.DieGroupManager.GetAll()) foreach ((string name, IEnumerable<Die> dice) in masterOfCeremonies.DieGroupManager.GetAll())
{ {
Console.WriteLine($"{name} -- {dice}"); Console.WriteLine($"{name} -- {dice}");
} }
@ -333,11 +333,11 @@ namespace App
return die; return die;
} }
private static IEnumerable<Die> PrepareDice(GameRunner gameRunner) private static IEnumerable<Die> PrepareDice(MasterOfCeremonies masterOfCeremonies)
{ {
List<Die> result = new(); List<Die> result = new();
Console.WriteLine("all known dice or groups of dice:"); Console.WriteLine("all known dice or groups of dice:");
ShowDice(gameRunner); ShowDice(masterOfCeremonies);
string menuChoiceDice = ""; string menuChoiceDice = "";
while (!(menuChoiceDice.Equals("ok") && result.Any())) while (!(menuChoiceDice.Equals("ok") && result.Any()))
{ {
@ -345,7 +345,7 @@ namespace App
menuChoiceDice = Console.ReadLine(); menuChoiceDice = Console.ReadLine();
if (!menuChoiceDice.Equals("ok")) if (!menuChoiceDice.Equals("ok"))
{ {
IEnumerable<Die> chosenDice = gameRunner.DieGroupManager.GetOneByName(menuChoiceDice).Value; IEnumerable<Die> chosenDice = masterOfCeremonies.DieGroupManager.GetOneByName(menuChoiceDice).Value;
foreach (Die die in chosenDice) foreach (Die die in chosenDice)
{ {
result.Add(die); result.Add(die);
@ -354,11 +354,11 @@ namespace App
} }
return result.AsEnumerable(); return result.AsEnumerable();
} }
private static PlayerManager PreparePlayers(GameRunner gameRunner) private static PlayerManager PreparePlayers(MasterOfCeremonies masterOfCeremonies)
{ {
PlayerManager result = new(); PlayerManager result = new();
Console.WriteLine("all known players:"); Console.WriteLine("all known players:");
ShowPlayers(gameRunner); ShowPlayers(masterOfCeremonies);
string menuChoicePlayers = ""; string menuChoicePlayers = "";
while (!(menuChoicePlayers.Equals("ok") && result.GetAll().Any())) while (!(menuChoicePlayers.Equals("ok") && result.GetAll().Any()))
{ {
@ -367,10 +367,10 @@ namespace App
if (!menuChoicePlayers.Equals("ok")) if (!menuChoicePlayers.Equals("ok"))
{ {
Player player = new(menuChoicePlayers); Player player = new(menuChoicePlayers);
if (!gameRunner.GlobalPlayerManager.GetAll().Contains(player)) if (!masterOfCeremonies.GlobalPlayerManager.GetAll().Contains(player))
{ {
// if the player didn't exist, now it does... this is temporary // if the player didn't exist, now it does... this is temporary
gameRunner.GlobalPlayerManager.Add(player); masterOfCeremonies.GlobalPlayerManager.Add(player);
} }
// almost no checks, this is temporary // almost no checks, this is temporary
try try

@ -6,7 +6,7 @@ namespace Data.EF
{ {
public class DiceAppDbContext : DbContext, ILoader public class DiceAppDbContext : DbContext, ILoader
{ {
public virtual GameRunner LoadApp() { throw new NotImplementedException(); } public virtual MasterOfCeremonies LoadApp() { throw new NotImplementedException(); }
public DbSet<PlayerEntity> Players { get; set; } public DbSet<PlayerEntity> Players { get; set; }

@ -7,7 +7,7 @@ namespace Data.EF
{ {
public class DiceAppDbContextWithStub : DiceAppDbContext public class DiceAppDbContextWithStub : DiceAppDbContext
{ {
public override GameRunner LoadApp() { throw new NotImplementedException(); } public override MasterOfCeremonies LoadApp() { throw new NotImplementedException(); }
public DiceAppDbContextWithStub() { } public DiceAppDbContextWithStub() { }

@ -4,6 +4,6 @@ namespace Data
{ {
public interface ILoader public interface ILoader
{ {
public GameRunner LoadApp(); public MasterOfCeremonies LoadApp();
} }
} }

@ -8,9 +8,9 @@ namespace Data
{ {
public class Stub : ILoader public class Stub : ILoader
{ {
public GameRunner LoadApp() public MasterOfCeremonies LoadApp()
{ {
GameRunner gr = new(new PlayerManager(), new DieManager(), new GameManager()); MasterOfCeremonies gr = new(new PlayerManager(), new DieManager(), new GameManager());
Player player1 = new("Alice(Old Stub)"), player2 = new("Bob(Old Stub)"), player3 = new("Clyde(Old Stub)"); Player player1 = new("Alice(Old Stub)"), player2 = new("Bob(Old Stub)"), player3 = new("Clyde(Old Stub)");

@ -19,7 +19,7 @@ namespace Model.Games
{ {
return name; return name;
} }
set // GameRunner will need to take care of forbidding set // MasterOfCeremonies will need to take care of forbidding
// (or allowing) having two Games with the same name etc. // (or allowing) having two Games with the same name etc.
{ {
if (string.IsNullOrWhiteSpace(value)) if (string.IsNullOrWhiteSpace(value))

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Games namespace Model.Games
{ {
@ -27,7 +25,7 @@ namespace Model.Games
/// <summary> /// <summary>
/// finds the game with that name and returns it /// finds the game with that name and returns it
/// <br/> /// <br/>
/// that copy does not belong to this gamerunner's games, so it should not be modified /// that copy does not belong to this manager's games, so it should not be modified
/// </summary> /// </summary>
/// <param name="name">a games's name</param> /// <param name="name">a games's name</param>
/// <returns>game with said name, <em>or null</em> if no such game was found</returns> /// <returns>game with said name, <em>or null</em> if no such game was found</returns>

@ -4,13 +4,13 @@ using System.Collections.Generic;
namespace Model.Games namespace Model.Games
{ {
public class GameRunner public class MasterOfCeremonies
{ {
public IManager<Player> GlobalPlayerManager { get; private set; } public IManager<Player> GlobalPlayerManager { get; private set; }
public IManager<KeyValuePair<string, IEnumerable<Die>>> DieGroupManager { get; private set; } public IManager<KeyValuePair<string, IEnumerable<Die>>> DieGroupManager { get; private set; }
public IManager<Game> GameManager { get; private set; } public IManager<Game> GameManager { get; private set; }
public GameRunner(IManager<Player> globalPlayerManager, IManager<KeyValuePair<string, IEnumerable<Die>>> globalDieManager, IManager<Game> gameManager) public MasterOfCeremonies(IManager<Player> globalPlayerManager, IManager<KeyValuePair<string, IEnumerable<Die>>> globalDieManager, IManager<Game> gameManager)
{ {
GlobalPlayerManager = globalPlayerManager; GlobalPlayerManager = globalPlayerManager;
DieGroupManager = globalDieManager; DieGroupManager = globalDieManager;

@ -15,7 +15,7 @@ namespace Tests.Model_UTs.Games
{ {
public class GameManagerTest public class GameManagerTest
{ {
private readonly GameRunner stubGameRunner = new Stub().LoadApp(); private readonly MasterOfCeremonies stubGameRunner = new Stub().LoadApp();
[Fact] [Fact]
public void TestConstructorReturnsEmptyEnumerable() public void TestConstructorReturnsEmptyEnumerable()

@ -1,47 +0,0 @@
using Data;
using Model.Dice;
using Model.Games;
using Model.Players;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace Tests.Model_UTs.Games
{
public class GameRunnerTest
{
private readonly GameRunner stubGameRunner = new Stub().LoadApp();
[Fact]
public void TestPlayGameWhenPlayThenAddNewTurnToHistory()
{
// Arrange
GameRunner gameRunner = stubGameRunner;
Game game = gameRunner.GameManager.GetAll().First();
// Act
int turnsBefore = game.GetHistory().Count();
GameRunner.PlayGame(game);
int turnsAfter = game.GetHistory().Count();
// Assert
Assert.Equal(turnsBefore + 1, turnsAfter);
}
[Fact]
public void TestStartNewGame()
{
// Arrange
GameRunner gameRunner = stubGameRunner;
string name = "blargh";
// Act
Assert.DoesNotContain(gameRunner.GameManager.GetOneByName(name), gameRunner.GameManager.GetAll());
gameRunner.StartNewGame(name, new PlayerManager(), stubGameRunner.GameManager.GetAll().First().Dice);
// Assert
Assert.Contains(gameRunner.GameManager.GetOneByName(name), gameRunner.GameManager.GetAll());
}
}
}

@ -13,15 +13,15 @@ namespace Tests.Model_UTs.Games
{ {
public class GameTest public class GameTest
{ {
private readonly GameRunner stubGameRunner = new Stub().LoadApp(); private readonly MasterOfCeremonies stubMasterOfCeremonies = new Stub().LoadApp();
private static readonly string GAME_NAME = "my game"; private static readonly string GAME_NAME = "my game";
private static readonly Player PLAYER_1 = new("Alice"), PLAYER_2 = new("Bob"), PLAYER_3 = new("Clyde"); private static readonly Player PLAYER_1 = new("Alice"), PLAYER_2 = new("Bob"), PLAYER_3 = new("Clyde");
private readonly IEnumerable<Die> DICE_1, DICE_2; private readonly IEnumerable<Die> DICE_1, DICE_2;
public GameTest() public GameTest()
{ {
DICE_1 = stubGameRunner.DieGroupManager.GetAll().First().Value; DICE_1 = stubMasterOfCeremonies.DieGroupManager.GetAll().First().Value;
DICE_2 = stubGameRunner.DieGroupManager.GetAll().Last().Value; DICE_2 = stubMasterOfCeremonies.DieGroupManager.GetAll().Last().Value;
} }
@ -81,7 +81,7 @@ namespace Tests.Model_UTs.Games
public void TestGetHistory() public void TestGetHistory()
{ {
// Arrange // Arrange
Dictionary<Die, Face> diceNFaces = (Dictionary<Die, Face>)stubGameRunner.GameManager.GetAll().First().GetHistory().First().DiceNFaces; Dictionary<Die, Face> diceNFaces = (Dictionary<Die, Face>)stubMasterOfCeremonies.GameManager.GetAll().First().GetHistory().First().DiceNFaces;
Turn turn1 = Turn.CreateWithDefaultTime(PLAYER_1, diceNFaces); Turn turn1 = Turn.CreateWithDefaultTime(PLAYER_1, diceNFaces);
Turn turn2 = Turn.CreateWithDefaultTime(PLAYER_2, diceNFaces); // yeah they rolled the same Turn turn2 = Turn.CreateWithDefaultTime(PLAYER_2, diceNFaces); // yeah they rolled the same

@ -0,0 +1,47 @@
using Data;
using Model.Dice;
using Model.Games;
using Model.Players;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace Tests.Model_UTs.Games
{
public class MasterOfCeremoniesTest
{
private readonly MasterOfCeremonies stubMasterOfCeremonies = new Stub().LoadApp();
[Fact]
public void TestPlayGameWhenPlayThenAddNewTurnToHistory()
{
// Arrange
MasterOfCeremonies masterOfCeremonies = stubMasterOfCeremonies;
Game game = masterOfCeremonies.GameManager.GetAll().First();
// Act
int turnsBefore = game.GetHistory().Count();
MasterOfCeremonies.PlayGame(game);
int turnsAfter = game.GetHistory().Count();
// Assert
Assert.Equal(turnsBefore + 1, turnsAfter);
}
[Fact]
public void TestStartNewGame()
{
// Arrange
MasterOfCeremonies masterOfCeremonies = stubMasterOfCeremonies;
string name = "blargh";
// Act
Assert.DoesNotContain(masterOfCeremonies.GameManager.GetOneByName(name), masterOfCeremonies.GameManager.GetAll());
masterOfCeremonies.StartNewGame(name, new PlayerManager(), stubMasterOfCeremonies.GameManager.GetAll().First().Dice);
// Assert
Assert.Contains(masterOfCeremonies.GameManager.GetOneByName(name), masterOfCeremonies.GameManager.GetAll());
}
}
}

@ -13,14 +13,14 @@ namespace Tests.Model_UTs.Games
public class TurnTest public class TurnTest
{ {
private readonly GameRunner stubGameRunner = new Stub().LoadApp(); private readonly MasterOfCeremonies stubMasterOfCeremonies = new Stub().LoadApp();
Dictionary<Die, Face> DICE_N_FACES_1, DICE_N_FACES_2; Dictionary<Die, Face> DICE_N_FACES_1, DICE_N_FACES_2;
public TurnTest() public TurnTest()
{ {
DICE_N_FACES_1 = (Dictionary<Die, Face>)stubGameRunner.GameManager.GetAll().First().GetHistory().First().DiceNFaces; DICE_N_FACES_1 = (Dictionary<Die, Face>)stubMasterOfCeremonies.GameManager.GetAll().First().GetHistory().First().DiceNFaces;
DICE_N_FACES_2 = (Dictionary<Die, Face>)stubGameRunner.GameManager.GetAll().Last().GetHistory().Last().DiceNFaces; DICE_N_FACES_2 = (Dictionary<Die, Face>)stubMasterOfCeremonies.GameManager.GetAll().Last().GetHistory().Last().DiceNFaces;
} }
[Fact] [Fact]

Loading…
Cancel
Save