コード例 #1
0
 /// <summary>
 /// Constructor: Initializes a CardDealer obkect
 /// </summary>
 /// <param name="cardCount">the number of cards the game is going to use</param>
 /// <throws>ArgumentOutOfRangeException if the number of cards is not 52, 36, or 20</throws>
 public CardDealer(int cardCount = 52)
 {
     // initalies the card list
     dealerCards = new CardList();
     // sets the number of cards
     NumberOfCards = cardCount;
 }
コード例 #2
0
 /// <summary>
 /// Utility method for copying card instances into another Cards instance-used in Deck.Shuffle().
 /// Ths implementation assumes that source and target collections are the same size.
 /// </summary>
 /// <param name="targetCards"></param>
 public void CopyTo(CardList targetCards)
 {
     for (int index = 0; index < this.Count; index++)
     {
         targetCards[index] = this[index];
     }
 }
コード例 #3
0
        /// <summary>
        /// Clone - Creates a copy of the Cards collection
        /// </summary>
        /// <returns>the new instance of the collection</returns>
        public object Clone()
        {
            CardList newCards = new CardList();   // creates a cards collection

            // copies each card using the depp copy from Card
            foreach (Card sourceCard in List)
            {
                newCards.Add((Card)sourceCard.Clone());
            }

            // returns the new collection
            return(newCards);
        }
コード例 #4
0
        CardList myCards;   // the list of cards

        /// <summary>
        /// Default Constructor: Initializes a deck of 52 cards
        /// </summary>
        public Deck()
        {
            myCards = new CardList();   // initializes a new list

            // runs through each suit
            for (int suitCount = 0; suitCount < 4; suitCount++)
            {
                // runs through each rank
                for (int rankCount = 2; rankCount < 15; rankCount++)
                {
                    // adds the card with the corresponding rank and suit to the list
                    myCards.Add(new Card((CardRank)rankCount, (CardSuit)suitCount));
                }
            }
        }