Example #1
0
        public void DoAction(int index, Hand hand)
        {
            switch (index)
            {
            case (int)PlayerAction.EndTurn:
            {
                ui.ShowEndTurn();
                PlayTurn(SwitchPlayer().NextTurn());
                return;
            }

            case (int)PlayerAction.EndGame:
            {
                PlayerDie(players[CurrentPlayerIndex], null);
                return;
            }
            }

            if (index >= 1 && index <= hand.Size)
            {
                var adjustedIndex = index - 1;
                var card          = hand.GetCard(adjustedIndex);
                if (card.Cost > players[CurrentPlayerIndex].CurrentMana)
                {
                    ui.ShowNoMana(card.Description);
                    PlayTurn(hand);
                }
                else
                {
                    hand = players[CurrentPlayerIndex].PlayCard(adjustedIndex);
                    ui.CardPlayed(players[CurrentPlayerIndex].Name, card.Description);

                    if (!string.IsNullOrWhiteSpace(card.Message))
                    {
                        ui.ShowMessage(card.Message);
                    }
                    foreach (var action in card.Actions)
                    {
                        switch (action.Type)
                        {
                        case ActionType.Damage:
                        {
                            players[OpponentIndex].GetDamage(action.Value);
                            ui.PlayerDamaged(players[OpponentIndex].Name, action.Value);
                            break;
                        }

                        case ActionType.Heal:
                        {
                            players[CurrentPlayerIndex].Heal(action.Value);
                            ui.PlayerHealed(players[CurrentPlayerIndex].Name, action.Value);
                            break;
                        }

                        case ActionType.Draw:
                        {
                            players[CurrentPlayerIndex].Draw(action.Value);
                            ui.PlayerDrawn(players[CurrentPlayerIndex].Name, action.Value);
                            break;
                        }

                        case ActionType.ManaAdd:
                        {
                            players[CurrentPlayerIndex].AddMana(action.Value);
                            ui.GotMana(players[CurrentPlayerIndex].Name, action.Value);
                            break;
                        }
                        }
                    }
                    PlayTurn(hand);
                }
            }
            else
            {
                ui.IncorrectChoice(index);
                PlayTurn(hand);
            }
        }