/// <summary> /// Removes a player from the formation /// </summary> /// <param name="player"></param> public void RemovePlayer(Player player) { var slot = Postitions.FirstOrDefault(x => x.Player == player); if (slot != null) { slot.Player = null; } else { throw new PlayerNotFoundException(); } }
/// <summary> /// Makes the position empty if there is any player in it /// </summary> /// <param name="positionNo">the position that will be emptied</param> public void EmptyPosition(int positionNo) { var slot = Postitions.FirstOrDefault(x => x.PositionNo == positionNo); if (slot != null) { slot.Player = null; } else { throw new PlayerNotFoundException(); } }
/// <summary> /// Adds a player to the first compatible position in the formation /// </summary> /// <param name="player"></param> public void AddPlayer(Player player) { GuardAgainstIncompatiblePlayer(player); var slot = Postitions.FirstOrDefault(x => x.Role == player.Role && x.IsEmpty); if (slot != null) { slot.Player = player; } else { throw new FormationSlotNotAvailableException(); } }
/// <summary> /// Adds a player to a specific slot in the formation /// </summary> /// <param name="player"></param> public void AddPlayer(Player player, int positionNo) { GuardAgainstIncompatiblePlayer(player); var slot = Postitions.Single(x => x.PositionNo == positionNo); if (!slot.IsEmpty) { throw new FormationSlotNotAvailableException(); } if (slot.Role != player.Role) { throw new FormationSlotIncompatibleException(); } slot.Player = player; }
/// <summary> /// Check if a player is currently in the formation /// </summary> /// <param name="player"></param> /// <returns>True if the player is in the formation</returns> public bool HasPlayer(Player player) { return(Postitions.Any(x => x.Player == player)); }