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

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

Let a player play a year of plenty development card If the player doesn't have a YearOfPlenty card on his hand a InsufficientResourcesException is thrown If the resource bank doesn't have enough cards to fulfill the request a NoMoreCardsException is thrown
public PlayYearOfPlenty ( Player player, Resource resource1, Resource resource2 ) : GameState
player Player The player playing the year of plenty development card
resource1 Resource The type of resource for the first card
resource2 Resource The type of resource for the second card
Результат GameState
        public GameState PlayYearOfPlenty(Player player, Resource resource1, Resource resource2)
        {
            var playable = GetPlayableDevelopmentCards(player);
            if (resourceBank[(int)resource1] == 0) throw new NoMoreCardsException("Resource bank is out of " + resource1);
            if (resourceBank[(int)resource2] == 0) throw new NoMoreCardsException("Resource bank is out of " + resource2);
            if (!playable.Contains(DevelopmentCard.YearOfPlenty)) throw new InsufficientResourcesException("No Year of Plenty found in hand");

            player.DevelopmentCards.Remove(DevelopmentCard.YearOfPlenty);
            GetResource(player, resource1);
            GetResource(player, resource2);

            Log(new PlayYearOfPlentyLogEvent(player.Id, resource1, resource2));

            return CurrentGamestate();
        }

Usage Example

Пример #1
0
 public GameState PlayYearOfPlenty(Resource resource1, Resource resource2)
 {
     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.PlayYearOfPlenty(player, resource1, resource2));
 }