Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <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();
                }
            }
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
 /// <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");
 }