/// <summary> /// When a card is played, it is added to the play pile of the deck. /// The effect of the card then takes place. /// </summary> /// <param name="cardId"></param> public override ActionResponse PlayCard(Card card, Player player) { ActionResponse res = new ActionResponse(); try { if (player.Id <= 0) { res = card.Play(); } else { res = card.Play(player); } } catch (Exception e) { res.AddError(e.Message); } if (res.IsSuccessful) { DiscardCard(card); } return(res); }
/// <summary> /// When a card is played, it is added to the play pile of the deck. /// The effect of the card then takes place. /// </summary> /// <param name="cardId"></param> public virtual ActionResponse PlayCard(Card card, Player player) { ActionResponse res = new ActionResponse(); if (Id == player.Id) { return(new ActionResponse(new Message(Enums.Severity.Error, "You can't play a card on yourself."))); } if (IsAskedForFavor) { return(new ActionResponse(new Message(Enums.Severity.Error, "You can't play a card when you're being asked for a favor."))); } if (IsBeingStolenFrom) { return(new ActionResponse(new Message(Enums.Severity.Error, "You can't play a card when you're being stolen from."))); } try { if (player.Id <= 0) { res = card.Play(); } else { res = card.Play(player); } } catch (Exception e) { res.AddError(e.Message); } if (res.IsSuccessful) { DiscardCard(card); } return(res); }
public ActionResponse Execute() { ActionResponse res = new ActionResponse(); if (!CurrentPlayer.Hand.HasSelectedCard) { res.AddError("You must select a card to play"); return(res); } Game.Writer.WriteLine(string.Format("Player {0} has played the card {1}\n", CurrentPlayer.Id, CurrentPlayer.Hand.SelectedCard.ToString())); bool isNoped = false; Player firstPlayer = CurrentPlayer; Player playerToNope = Game.NextPlayer; while (playerToNope != firstPlayer) { Game.Writer.WriteLine(string.Format("Player {0}, would you like to 'Nope'? (y/n)\n", playerToNope.Id)); bool hasChosen = false; while (!hasChosen) { string choice = Console.ReadLine(); Game.Writer.WriteLine(); if (choice == "y" || choice == "n") { hasChosen = true; if (choice == "y") { Card nope = playerToNope.Hand.GetNope(); ActionResponse nopeRes = playerToNope.PlayCard(nope); if (nopeRes.IsSuccessful) { isNoped = !isNoped; firstPlayer = playerToNope; playerToNope = Game.GetNextPlayer(firstPlayer); } else { nopeRes.PrintErrors(); playerToNope = Game.GetNextPlayer(playerToNope); } } else { playerToNope = Game.GetNextPlayer(playerToNope); } } } } if (isNoped) { res.AddMessage(string.Format("Player {0}'s card ({1}) was successfully 'Noped'.\n", CurrentPlayer.Id, CurrentPlayer.Hand.SelectedCard.Name)); CurrentPlayer.DiscardCard(CurrentPlayer.Hand.SelectedCard); } else if (CurrentTargetPlayerIndex <= 0) { res = CurrentPlayer.PlayCard(CurrentPlayer.Hand.SelectedCard); } else { res = CurrentPlayer.PlayCard(CurrentPlayer.Hand.SelectedCard, Game.GetSelectedPlayer(CurrentTargetPlayerIndex)); } return(res); }