♻️ Rename DieManager to DiceGroupManager
continuous-integration/drone/push Build is passing Details

that class is in charge of managing groups of dice (in association with a string name)
pull/126/head
Alexis Drai 2 years ago
parent a28149ec29
commit 1f2ca7483f

@ -28,7 +28,7 @@ namespace App
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
masterOfCeremonies = new(new PlayerManager(), new DieManager(), null);
masterOfCeremonies = new(new PlayerManager(), new DiceGroupManager(), null);
}
try
@ -90,7 +90,7 @@ namespace App
case "n":
if (!masterOfCeremonies.DieGroupManager.GetAll().Any())
if (!masterOfCeremonies.DiceGroupManager.GetAll().Any())
{
Console.WriteLine("make at least one dice group first, then try again");
break;
@ -151,7 +151,7 @@ namespace App
newGroupDice.Add(die);
}
}
masterOfCeremonies.DieGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(newGroupName, newGroupDice));
masterOfCeremonies.DiceGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(newGroupName, newGroupDice));
break;
case "p":
@ -257,7 +257,7 @@ namespace App
private static void ShowDice(MasterOfCeremonies masterOfCeremonies)
{
foreach ((string name, IEnumerable<Die> dice) in masterOfCeremonies.DieGroupManager.GetAll())
foreach ((string name, IEnumerable<Die> dice) in masterOfCeremonies.DiceGroupManager.GetAll())
{
Console.WriteLine($"{name} -- {dice}");
}
@ -345,7 +345,7 @@ namespace App
menuChoiceDice = Console.ReadLine();
if (!menuChoiceDice.Equals("ok"))
{
IEnumerable<Die> chosenDice = masterOfCeremonies.DieGroupManager.GetOneByName(menuChoiceDice).Value;
IEnumerable<Die> chosenDice = masterOfCeremonies.DiceGroupManager.GetOneByName(menuChoiceDice).Value;
foreach (Die die in chosenDice)
{
result.Add(die);

@ -10,7 +10,7 @@ namespace Data
{
public MasterOfCeremonies LoadApp()
{
MasterOfCeremonies gr = new(new PlayerManager(), new DieManager(), new GameManager());
MasterOfCeremonies gr = new(new PlayerManager(), new DiceGroupManager(), new GameManager());
Player player1 = new("Alice(Old Stub)"), player2 = new("Bob(Old Stub)"), player3 = new("Clyde(Old Stub)");
@ -63,8 +63,8 @@ namespace Data
dndDice.Add(new NumberDie(d20Faces));
gr.DieGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(dndName, dndDice.AsEnumerable()));
gr.DieGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(monopolyName, monopolyDice.AsEnumerable()));
gr.DiceGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(dndName, dndDice.AsEnumerable()));
gr.DiceGroupManager.Add(new KeyValuePair<string, IEnumerable<Die>>(monopolyName, monopolyDice.AsEnumerable()));
string game1 = "Forgotten Realms", game2 = "4e", game3 = "The Coopers";

@ -1,87 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Model.Dice
{
public class DieManager : IManager<KeyValuePair<string, IEnumerable<Die>>>
{
private readonly Dictionary<string, IEnumerable<Die>> diceGroups = new();
public KeyValuePair<string, IEnumerable<Die>> Add(KeyValuePair<string, IEnumerable<Die>> toAdd)
{
if (string.IsNullOrWhiteSpace(toAdd.Key))
{
throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty");
}
if (diceGroups.Contains(toAdd))
{
throw new ArgumentException("this username is already taken", nameof(toAdd));
}
diceGroups.Add(toAdd.Key.Trim(), toAdd.Value);
return toAdd;
}
public IEnumerable<KeyValuePair<string, IEnumerable<Die>>> GetAll()
{
return diceGroups.AsEnumerable();
}
public KeyValuePair<string, IEnumerable<Die>> GetOneByID(Guid ID)
{
throw new NotImplementedException();
}
public KeyValuePair<string, IEnumerable<Die>> GetOneByName(string name)
{
// les groupes de dés nommés :
// ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu"
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentNullException(nameof(name), "param should not be null or empty");
}
else
{
return new KeyValuePair<string, IEnumerable<Die>>(name, diceGroups[name]);
}
}
public void Remove(KeyValuePair<string, IEnumerable<Die>> toRemove)
{
if (toRemove.Key is null)
{
throw new ArgumentNullException(nameof(toRemove), "param should not be null");
}
else
{
diceGroups.Remove(toRemove.Key);
}
}
/// <summary>
/// updates a (string, IEnumerable-of-Die) couple. only the name can be updated
/// </summary>
/// <param name="before">original couple</param>
/// <param name="after">new couple</param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="ArgumentNullException"></exception>
public KeyValuePair<string, IEnumerable<Die>> Update(KeyValuePair<string, IEnumerable<Die>> before, KeyValuePair<string, IEnumerable<Die>> after)
{
// pas autorisé de changer les dés, juste le nom
if (!before.Value.Equals(after.Value))
{
throw new ArgumentException("the group of dice cannot be updated, only the name", nameof(before));
}
if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key))
{
throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty");
}
diceGroups.Remove(before.Key);
diceGroups.Add(after.Key, after.Value);
return after;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
namespace Model.Dice
{
public class DiceGroupManager : IManager<KeyValuePair<string, IEnumerable<Die>>>
{
private readonly Dictionary<string, IEnumerable<Die>> diceGroups = new();
public KeyValuePair<string, IEnumerable<Die>> Add(KeyValuePair<string, IEnumerable<Die>> toAdd)
{
if (string.IsNullOrWhiteSpace(toAdd.Key))
{
throw new ArgumentNullException(nameof(toAdd), "param should not be null or empty");
}
if (diceGroups.Contains(toAdd))
{
throw new ArgumentException("this username is already taken", nameof(toAdd));
}
diceGroups.Add(toAdd.Key.Trim(), toAdd.Value);
return toAdd;
}
public IEnumerable<KeyValuePair<string, IEnumerable<Die>>> GetAll()
{
return diceGroups.AsEnumerable();
}
public KeyValuePair<string, IEnumerable<Die>> GetOneByID(Guid ID)
{
throw new NotImplementedException();
}
public KeyValuePair<string, IEnumerable<Die>> GetOneByName(string name)
{
// les groupes de dés nommés :
// ils sont case-sensistive, mais "mon jeu" == "mon jeu " == " mon jeu"
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentNullException(nameof(name), "param should not be null or empty");
}
else
{
return new KeyValuePair<string, IEnumerable<Die>>(name, diceGroups[name]);
}
}
public void Remove(KeyValuePair<string, IEnumerable<Die>> toRemove)
{
if (toRemove.Key is null)
{
throw new ArgumentNullException(nameof(toRemove), "param should not be null");
}
else
{
diceGroups.Remove(toRemove.Key);
}
}
/// <summary>
/// updates a (string, IEnumerable-of-Die) couple. only the name can be updated
/// </summary>
/// <param name="before">original couple</param>
/// <param name="after">new couple</param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="ArgumentNullException"></exception>
public KeyValuePair<string, IEnumerable<Die>> Update(KeyValuePair<string, IEnumerable<Die>> before, KeyValuePair<string, IEnumerable<Die>> after)
{
// pas autorisé de changer les dés, juste le nom
if (!before.Value.Equals(after.Value))
{
throw new ArgumentException("the group of dice cannot be updated, only the name", nameof(before));
}
if (string.IsNullOrWhiteSpace(before.Key) || string.IsNullOrWhiteSpace(after.Key))
{
throw new ArgumentNullException(nameof(before), "dice group name should not be null or empty");
}
diceGroups.Remove(before.Key);
diceGroups.Add(after.Key, after.Value);
return after;
}
}
}

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

@ -20,8 +20,8 @@ namespace Tests.Model_UTs.Games
private readonly IEnumerable<Die> DICE_1, DICE_2;
public GameTest()
{
DICE_1 = stubMasterOfCeremonies.DieGroupManager.GetAll().First().Value;
DICE_2 = stubMasterOfCeremonies.DieGroupManager.GetAll().Last().Value;
DICE_1 = stubMasterOfCeremonies.DiceGroupManager.GetAll().First().Value;
DICE_2 = stubMasterOfCeremonies.DiceGroupManager.GetAll().Last().Value;
}

Loading…
Cancel
Save