Ejemplo n.º 1
0
        protected void DiscardCards(int playerId, IGameState gameState, IActionCost actionCost)
        {
            Logger?.LogInformation("Discarding cards.");

            var player = gameState.Players.Single(p => p.PlayerId == playerId);

            foreach (var card in actionCost.Cards)
            {
                player.RemoveCard(card.CardId);
                gameState.DiscardCard(card);
            }
        }
Ejemplo n.º 2
0
        public Task ExecuteActionAsync(int playerId, IGameState gameState, IActionCost actionCost = null)
        {
            _logger?.LogInformation("Drawing a card...");
            var newCard = gameState.DrawCard();

            gameState.Players.Single(p => p.PlayerId == playerId).AddCard(newCard);

            if (newCard.Family == CardFamily.Lose)
            {
                gameState.CurrentPhase = TurnPhase.Elimination;
            }
            else
            {
                gameState.CurrentPhase = TurnPhase.TurnEnd;
            }
            return(Task.CompletedTask);
        }
Ejemplo n.º 3
0
        public Task ExecuteActionAsync(int playerId, IGameState gameState, IActionCost actionCost)
        {
            _logger?.LogInformation("Using extra life and returning lose card.");

            if (actionCost is null)
            {
                throw new ArgumentNullException(nameof(actionCost));
            }

            if (actionCost.Cards.Count != 2)
            {
                throw new InvalidOperationException("Action cost for an extra life action must be two cards.");
            }

            var playedCard = actionCost.Cards.First();

            if (playedCard.Family != CostCardFamily)
            {
                throw new InvalidOperationException($"Action requires a cost of one card from family {CostCardFamily} and must be the first action cost card.");
            }

            var loseCard = actionCost.Cards.ElementAt(1);

            if (loseCard.Family != ReturnCardFamily)
            {
                throw new InvalidOperationException($"Action requires a cost of one card from family {ReturnCardFamily} and must be the second action cost card.");
            }

            var player = gameState.Players.Single(p => p.PlayerId == playerId);

            player.RemoveCard(playedCard.CardId);
            gameState.DiscardCard(playedCard);

            // TODO: Let player choose where instead of randomly.
            player.RemoveCard(loseCard.CardId);
            gameState.ReturnToDeck(loseCard, new Random().Next(gameState.Deck.Count + 1));
            return(Task.CompletedTask);
        }
Ejemplo n.º 4
0
        public Task ExecuteActionAsync(int playerId, IGameState gameState, IActionCost actionCost)
        {
            if (actionCost is null)
            {
                throw new ArgumentNullException(nameof(actionCost));
            }

            if (actionCost.Cards.Count != 1)
            {
                throw new InvalidOperationException("Action cost for a single card action must only contain one card.");
            }

            var playedCard = actionCost.Cards.Single();

            if (playedCard.Family != RequiredCardFamily)
            {
                throw new InvalidOperationException($"Action requires a cost of one card from family {RequiredCardFamily}.");
            }

            gameState.Players.Single(p => p.PlayerId == playerId).RemoveCard(playedCard.CardId);
            gameState.DiscardCard(playedCard);

            return(ExecuteActionCoreAsync(gameState));
        }
Ejemplo n.º 5
0
 public Task ExecuteActionAsync(int playerId, IGameState gameState, IActionCost actionCost)
 {
     DiscardCards(playerId, gameState, actionCost);
     return(ExecuteCoreAsync(gameState));
 }