diff --git a/Sources/Model/PlayerManager.cs b/Sources/Model/PlayerManager.cs index 9c552cb..cafabd6 100644 --- a/Sources/Model/PlayerManager.cs +++ b/Sources/Model/PlayerManager.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,25 +10,84 @@ namespace Model { public class PlayerManager : IManager { - public Player Add(ref Player toAdd) + /// + /// a hashset of the players that this manager is in charge of + ///
+ /// the hash is based on the player's unique property (name) + ///
+ private readonly HashSet players; + + public PlayerManager() { - throw new NotImplementedException(); + players = new HashSet(); } - public IEnumerable GetAll() + /// + /// add a new player + /// + /// player to be added + /// added player, or null if was null + public Player Add(ref Player toAdd) { - throw new NotImplementedException(); + if (toAdd != null) + { + players.Add(toAdd); + } + return toAdd; } + + /// + /// may never get implemented in the model, go through GetOneByName() in the meantime + /// + /// + /// + /// public Player GetOneById(int id) { - throw new NotImplementedException(); + throw new NotImplementedException("may never get implemented\ngo through GetOneByName() in the meantime"); } - public void Remove(ref Player toRemove) + + /// + /// finds the player with that name and returns A COPY OF IT + ///
+ /// that copy does not belong to this manager's players, so it should not be modified + ///
+ /// a player's unique name + /// player with said name + public Player GetOneByName(string name) { - throw new NotImplementedException(); + if (!String.IsNullOrEmpty(name)) + { + Player result = players.Where(p => p.Name.Equals(name)).FirstOrDefault(); + return new Player(result.Name); // will return null if no such player exists + } + return null; // we also want ot return null if no name was provided } + + /// + /// get a READ ONLY enumerable of all players belonging to this manager + /// + /// a readonly list of all this manager's players + public IEnumerable GetAll() => players.AsEnumerable(); + + /// + /// update a player from to + /// + /// player to be updated + /// player in the state that it needs to be in after the update + /// updated player public Player Update(ref Player before, ref Player after) { - throw new NotImplementedException(); + Remove(ref before); + return Add(ref after); + } + + /// + /// remove a player + /// + /// player to be removed + public void Remove(ref Player toRemove) + { + players.Remove(toRemove); } } }