Example #1
0
        public static string ToFriendlyString(this PlayingCardSuit suit)
        {
            string str;

            if (suit == PlayingCardSuit.None)
            {
                str = suit.ToString();
            }
            else
            {
                switch (suit)
                {
                case PlayingCardSuit.Hearts:
                    str = "♡";
                    break;

                case PlayingCardSuit.Diamonds:
                    str = "♦";
                    break;

                case PlayingCardSuit.Spades:
                    str = "♠";
                    break;

                case PlayingCardSuit.Clubs:
                    str = "♧";
                    break;

                default:
                    str = suit.ToString();
                    break;
                }
            }
            return(str);
        }
Example #2
0
 public PlayingCard DrawCard(PlayingCardSuit suit)
 {
     lock (m_cardsRemaining)
     {
         var possibleCards = m_cardsRemaining.FindAll(card => card.Suit == suit);
         if (possibleCards.Count < 1)
         {
             return(null);
         }
         var cardPick   = m_Random.Next(possibleCards.Count);
         var pickedCard = possibleCards[cardPick];
         m_cardsRemaining.Remove(pickedCard);
         return(pickedCard);
     }
 }
Example #3
0
        /// <summary>
        /// Build a standard deck of 52 playing cards
        /// </summary>
        /// <returns></returns>
        public static IList <PlayingCard> BuildDeck()
        {
            var deck = new List <PlayingCard>(52);

            for (PlayingCardSuit suit = PlayingCardSuit.Spades;
                 suit <= PlayingCardSuit.Clubs; suit++)
            {
                for (PlayingCardRank rank = PlayingCardRank.Ace;
                     rank <= PlayingCardRank.King; rank++)
                {
                    deck.Add(new PlayingCard(rank, suit));
                }
            }
            return(deck);
        }
Example #4
0
 public PlayingCard(PlayingCardSuit suit, PlayingCardValue suitValue)
 {
     Suit      = suit;
     SuitValue = suitValue;
 }
 public PlayingCard(int id, PlayingCardSuit suit, PlayingCardRank rank)
 {
     Id   = id;
     Suit = suit;
     Rank = rank;
 }
 public PlayingCard(PlayingCardRank rank, PlayingCardSuit suit)
 {
     Rank = rank;
     Suit = suit;
 }
Example #7
0
        public static PlayingCard AllButHighestCardOfSuit(this IEnumerable <PlayingCard> cards, PlayingCardSuit suit, bool aceRankHigh = true)
        {
            var comparer = new PlayingCardRankComparer {
                AceRankHigh = aceRankHigh
            };
            var cardsOfSuit = cards.Where(x => x.Suit == suit).OrderByDescending(x => x.Rank, comparer).ToList();
            var result      = cardsOfSuit.FirstOrDefault();

            return(result);
        }
Example #8
0
 /// <summary>
 /// Creates a playing card.
 /// </summary>
 /// <param name="options">The options on how cards are played.</param>
 /// <param name="suit">The suit of the card.</param>
 /// <param name="rank">The rank of the card.</param>
 internal PlayingCard(PlayingCardOptions options, PlayingCardSuit suit, PlayingCardRank rank)
 {
     Rank    = rank;
     Suit    = suit;
     Options = options;
 }
Example #9
0
 public PlayingCard(char cardValue, char cardSuit)
 {
     CardValue = CreateCardValue(cardValue);
     CardSuit  = CreateCardSuit(cardSuit);
 }
Example #10
0
        public void PlayingCard_ConvertsSuitToEnum(char cardSuit, PlayingCardSuit expectedSuit)
        {
            var playingCard = new PlayingCard('2', cardSuit);

            Assert.AreEqual(expectedSuit, playingCard.CardSuit);
        }
 public PlayingCard(PlayingCardSuit suit, PlayingCardRank rank)
 {
     Suit = suit;
     Rank = rank;
 }
Example #12
0
 public static string AsString(this PlayingCardSuit value) => Strings[value];