AIsOfCatan.GameController.DrawDevelopmentCard C# (CSharp) Метод

DrawDevelopmentCard() публичный Метод

Let a player draw a development card If the player doesn't have enough resources a InsufficientResourcesException is thrown If the development card stack is empty a NoMoreCardsException is thrown Resources to pay for the card are removed from the player hand and returned to the resource bank
public DrawDevelopmentCard ( Player player ) : GameState
player Player The player drawing a development card
Результат GameState
        public GameState DrawDevelopmentCard(Player player)
        {
            var r = player.Resources;
            if (!(r.Contains(Resource.Grain) && r.Contains(Resource.Wool) && r.Contains(Resource.Ore)))
                throw new InsufficientResourcesException("Not enough resources to buy a development card");

            if (developmentCardStack.Count == 0)
                throw new NoMoreCardsException("Development card stack is empty");

            PayResource(player, Resource.Grain);
            PayResource(player, Resource.Wool);
            PayResource(player, Resource.Ore);

            var last = developmentCardStack.Last();
            developmentCardStack.RemoveAt(developmentCardStack.Count-1);

            Log(new BuyDevLogEvent(player.Id));

            player.DevelopmentCards.Add(last);
            player.NewDevelopmentCards.Add(last);
            return CurrentGamestate();
        }

Usage Example

Пример #1
0
        //Development cards

        public GameState DrawDevelopmentCard()
        {
            if (!valid)
            {
                throw new IllegalActionException("Tried to perform an action on an invalid GameAction");
            }
            if (!isAfterDieRoll)
            {
                throw new IllegalActionException("Tried to draw developmentcard before the die roll");
            }
            var result = controller.DrawDevelopmentCard(player);

            return(result);
        }