AIsOfCatan.GameController.PlayKnight C# (CSharp) Method

PlayKnight() public method

Let a player play a knight development card If the player doesn't have a knight on his hand a InsufficientResourcesException is thrown A knight is removed from the players hand The largest army special card is relocated if playing this knight causes it to be
public PlayKnight ( Player player ) : GameState
player Player The player playing a knight
return GameState
        public GameState PlayKnight(Player player)
        {
            var playable = GetPlayableDevelopmentCards(player);
            if (!playable.Contains(DevelopmentCard.Knight))
                throw new InsufficientResourcesException("No knight found in hand");

            player.DevelopmentCards.Remove(DevelopmentCard.Knight);
            player.PlayedKnights++;
            if (player.PlayedKnights > largestArmySize)
            {
                largestArmySize = player.PlayedKnights;
                largestArmyId = player.Id;
            }

            MoveRobber(player, CurrentGamestate());

            Log(new PlayKnightLogEvent(player.Id));

            return CurrentGamestate();
        }

Usage Example

Example #1
0
 public GameState PlayKnight()
 {
     if (!valid)
     {
         throw new IllegalActionException("Tried to perform an action on an invalid GameAction");
     }
     if (hasPlayedDevCard)
     {
         throw new IllegalActionException("Max one development card can be played each turn");
     }
     hasPlayedDevCard = true;
     return(controller.PlayKnight(player));
 }