Exemplo n.º 1
0
        /// <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();
            }
        }
Exemplo n.º 2
0
        /// <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();
            }
        }
Exemplo n.º 3
0
        /// <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();
            }
        }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
 /// <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));
 }