示例#1
0
        /// <summary>
        /// Default constructor for a deck of cards.
        /// </summary>
        public Deck()
        {
            foreach (CardRank rank in (CardRank[])Enum.GetValues(typeof(CardRank)))     // for each rank in the Rank enum
            {
                foreach (CardSuit suit in (CardSuit[])Enum.GetValues(typeof(CardSuit))) // for each suit in the Suit enum
                {
                    cards.Add(new PlayingCard(suit, rank));
                }
            }

            // move the aces in front of the kings, that is the order or ranks in Durak
            for (int cardIndex = 0; cardIndex < 4; cardIndex++)
            {
                PlayingCard cardToMove = cards[0];
                cards.RemoveAt(0);
                cards.Add(cardToMove);
            }
        }
示例#2
0
文件: Deck.cs 项目: alto4/CardLib
 /// <summary>
 /// return the card at the param index and remove it from the deck
 /// </summary>
 /// <param name="cardIndex">The cards index</param>
 /// <returns>The Card at this index</returns>
 public PlayingCard DrawCard(int cardIndex = 0)
 {
     if (cardIndex >= 0 && cardIndex <= 51)
     {
         PlayingCard tempCard = cards[cardIndex];
         cards.RemoveAt(cardIndex);
         return(cards[cardIndex]); // card number 0 to SIZE_OF_DECK
     }
     else
     {
         throw new IndexOutOfRangeException(string.Format(" * Card index must be between {0} and {1}", 0, SIZE_OF_DECK - 1));
     }
 }