🐛 Change 2-tuple to dictionary
continuous-integration/drone/push Build is passing Details

pull/81/head
Alexis Drai 3 years ago
parent 88f7193033
commit 535631e0e1

@ -20,14 +20,12 @@ namespace Data
Player player1 = new("Alice"), player2 = new("Bob"), player3 = new("Clyde"); Player player1 = new("Alice"), player2 = new("Bob"), player3 = new("Clyde");
IManager<(string, IEnumerable<AbstractDie<AbstractDieFace>>)> globalDieManager = new DieManager(); IManager<KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>> globalDieManager = new DieManager();
// create at least one group in there // create at least one group in there
// ... // ...
IEnumerable<AbstractDie<AbstractDieFace>> dice1; IEnumerable<AbstractDie<AbstractDieFace>> dice1 = globalDieManager.GetAll().First().Value;
(_, dice1) = globalDieManager.GetAll().First(); IEnumerable<AbstractDie<AbstractDieFace>> dice2 = globalDieManager.GetAll().Last().Value;
IEnumerable<AbstractDie<AbstractDieFace>> dice2;
(_, dice2) = globalDieManager.GetAll().Last();
Game game1 = new(name: g1, playerManager: new PlayerManager(), dice: dice1); Game game1 = new(name: g1, playerManager: new PlayerManager(), dice: dice1);
Game game2 = new(name: g2, playerManager: new PlayerManager(), dice: dice2); Game game2 = new(name: g2, playerManager: new PlayerManager(), dice: dice2);

@ -1,35 +1,41 @@
using Model.Dice.Faces; using Model.Dice.Faces;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace Model.Dice namespace Model.Dice
{ {
public class DieManager : IManager<(string, IEnumerable<AbstractDie<AbstractDieFace>>)> public class DieManager : IManager<KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>>
{ {
private readonly List<(string name, IEnumerable<AbstractDie<AbstractDieFace>> dice)> diceGroups = new(); private readonly Dictionary<string, IEnumerable<AbstractDie<AbstractDieFace>>> diceGroups = new();
public (string, IEnumerable<AbstractDie<AbstractDieFace>>) Add((string, IEnumerable<AbstractDie<AbstractDieFace>>) toAdd) public KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> Add(KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> toAdd)
{ {
throw new System.NotImplementedException(); diceGroups.Add(toAdd.Key, toAdd.Value);
return toAdd;
} }
public IEnumerable<(string, IEnumerable<AbstractDie<AbstractDieFace>>)> GetAll() public IEnumerable<KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>> GetAll()
{ {
throw new System.NotImplementedException(); return diceGroups.AsEnumerable();
} }
public (string, IEnumerable<AbstractDie<AbstractDieFace>>) GetOneByName(string name) public KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> GetOneByName(string name)
{ {
throw new System.NotImplementedException(); return new KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>(name, diceGroups[name]);
} }
public void Remove((string, IEnumerable<AbstractDie<AbstractDieFace>>) toRemove) public void Remove(KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> toRemove)
{ {
throw new System.NotImplementedException(); diceGroups.Remove(toRemove.Key);
} }
public (string, IEnumerable<AbstractDie<AbstractDieFace>>) Update((string, IEnumerable<AbstractDie<AbstractDieFace>>) before, (string, IEnumerable<AbstractDie<AbstractDieFace>>) after) public KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> Update(KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> before, KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>> 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;
} }
} }
} }

@ -12,10 +12,10 @@ namespace Model.Games
public class GameRunner public class GameRunner
{ {
private readonly IManager<Player> globalPlayerManager; private readonly IManager<Player> globalPlayerManager;
private readonly IManager<(string, IEnumerable<AbstractDie<AbstractDieFace>>)> globalDieManager; private readonly IManager<KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>> globalDieManager;
private readonly List<Game> games; private readonly List<Game> games;
public GameRunner(IManager<Player> globalPlayerManager, IManager<(string, IEnumerable<AbstractDie<AbstractDieFace>>)> globalDieManager, List<Game> games) public GameRunner(IManager<Player> globalPlayerManager, IManager<KeyValuePair<string, IEnumerable<AbstractDie<AbstractDieFace>>>> globalDieManager, List<Game> games)
{ {
this.globalPlayerManager = globalPlayerManager; this.globalPlayerManager = globalPlayerManager;
this.globalDieManager = globalDieManager; this.globalDieManager = globalDieManager;

Loading…
Cancel
Save