From 535631e0e144889651c0bd830513982f6c604c1a Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Sat, 24 Sep 2022 23:13:17 +0200 Subject: [PATCH] :bug: Change 2-tuple to dictionary --- Sources/Data/Stub.cs | 8 +++----- Sources/Model/Dice/DieManager.cs | 30 ++++++++++++++++++------------ Sources/Model/Games/GameRunner.cs | 4 ++-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Sources/Data/Stub.cs b/Sources/Data/Stub.cs index 29f2ef7..0cf49db 100644 --- a/Sources/Data/Stub.cs +++ b/Sources/Data/Stub.cs @@ -20,14 +20,12 @@ namespace Data Player player1 = new("Alice"), player2 = new("Bob"), player3 = new("Clyde"); - IManager<(string, IEnumerable>)> globalDieManager = new DieManager(); + IManager>>> globalDieManager = new DieManager(); // create at least one group in there // ... - IEnumerable> dice1; - (_, dice1) = globalDieManager.GetAll().First(); - IEnumerable> dice2; - (_, dice2) = globalDieManager.GetAll().Last(); + IEnumerable> dice1 = globalDieManager.GetAll().First().Value; + IEnumerable> dice2 = globalDieManager.GetAll().Last().Value; Game game1 = new(name: g1, playerManager: new PlayerManager(), dice: dice1); Game game2 = new(name: g2, playerManager: new PlayerManager(), dice: dice2); diff --git a/Sources/Model/Dice/DieManager.cs b/Sources/Model/Dice/DieManager.cs index a26a83d..92da094 100644 --- a/Sources/Model/Dice/DieManager.cs +++ b/Sources/Model/Dice/DieManager.cs @@ -1,35 +1,41 @@ using Model.Dice.Faces; using System.Collections.Generic; +using System.Linq; namespace Model.Dice { - public class DieManager : IManager<(string, IEnumerable>)> + public class DieManager : IManager>>> { - private readonly List<(string name, IEnumerable> dice)> diceGroups = new(); + private readonly Dictionary>> diceGroups = new(); - public (string, IEnumerable>) Add((string, IEnumerable>) toAdd) + public KeyValuePair>> Add(KeyValuePair>> toAdd) { - throw new System.NotImplementedException(); + diceGroups.Add(toAdd.Key, toAdd.Value); + return toAdd; } - public IEnumerable<(string, IEnumerable>)> GetAll() + public IEnumerable>>> GetAll() { - throw new System.NotImplementedException(); + return diceGroups.AsEnumerable(); } - public (string, IEnumerable>) GetOneByName(string name) + public KeyValuePair>> GetOneByName(string name) { - throw new System.NotImplementedException(); + return new KeyValuePair>>(name, diceGroups[name]); } - public void Remove((string, IEnumerable>) toRemove) + public void Remove(KeyValuePair>> toRemove) { - throw new System.NotImplementedException(); + diceGroups.Remove(toRemove.Key); } - public (string, IEnumerable>) Update((string, IEnumerable>) before, (string, IEnumerable>) after) + public KeyValuePair>> Update(KeyValuePair>> before, KeyValuePair>> after) { - throw new System.NotImplementedException(); + // check if key 1 exists + // check if both keys same + diceGroups.Remove(before.Key); + diceGroups.Add(after.Key, after.Value); + return after; } } } diff --git a/Sources/Model/Games/GameRunner.cs b/Sources/Model/Games/GameRunner.cs index ff91687..070cdff 100644 --- a/Sources/Model/Games/GameRunner.cs +++ b/Sources/Model/Games/GameRunner.cs @@ -12,10 +12,10 @@ namespace Model.Games public class GameRunner { private readonly IManager globalPlayerManager; - private readonly IManager<(string, IEnumerable>)> globalDieManager; + private readonly IManager>>> globalDieManager; private readonly List games; - public GameRunner(IManager globalPlayerManager, IManager<(string, IEnumerable>)> globalDieManager, List games) + public GameRunner(IManager globalPlayerManager, IManager>>> globalDieManager, List games) { this.globalPlayerManager = globalPlayerManager; this.globalDieManager = globalDieManager;