/// <summary> /// Check if a new card is the new winner. /// </summary> private bool IsNewCardWinner(EnglishCard winningCard, EnglishCard newCard) { if (newCard.Suit == Triunfo.Suit && winningCard.Suit != Triunfo.Suit) { return(true); } if (newCard.Suit == winningCard.Suit && newCard.Rank > winningCard.Rank) { return(true); } return(false); }
/// <summary> /// Validates a card. /// </summary> private bool IsValidCard(BazasPlayerStatus status, EnglishCard card) { if (status.Cards.Contains(card)) { if (handPlayerIndex > 0 && card.Suit != HandCards[0].Suit) { return(!status.Cards.Any(c => c.Suit == HandCards[0].Suit)); } return(true); } return(false); }
/// <summary> /// Plays a card. /// </summary> public void PlayCard(Player player, EnglishCard card) { if (State == BazasState.Play && player == CurrPlayer) { if (GetPlayerStatus(player, out BazasPlayerStatus status)) { if (!IsValidCard(status, card)) { throw new Exception(string.Format("No podés jugar {0}.", card)); } HandCards[handPlayerIndex] = card; status.Cards.Remove(card); NextStep(); } } }
/// <summary> /// Calculates winner. /// </summary> private Player CalcHandWinner() { EnglishCard winningCard = null; Player winner = null; for (var index = 0; index < PlayersNumber; index++) { var playerCard = HandCards[index]; if (index == 0 || IsNewCardWinner(winningCard, playerCard)) { winningCard = playerCard; winner = HandPlayers[index]; } } return(winner); }
/// <summary> /// Gets a card file name. /// </summary> public string GetCardFile(EnglishCard card) { return(card != null ? $"/Images/EnglishCards/{card.GetSuitText()}_{card.GetRankText()}.svg" : $"/Images/EnglishCards/reverse.svg"); }