Exemple #1
0
        /// <summary>
        /// This method performs a deep copy of the Deck object, creating new instances of
        /// all its members.
        /// </summary>
        /// <returns>An object matching this Deck object.</returns>
        public object Clone()
        {
            // The cards field needs to be cloned to ensure we get new instances. This
            // clone will be passed to the private constructor of this Deck class to create
            // a new deck instance with a collection of new card instances in the same order
            // as this deck. Since the Clone() method returns a generic object, we need to
            // cast it as a Cards object to satisy the Deck constructor.
            Deck newDeck = new Deck(cards.Clone() as Cards);

            return(newDeck);
        }
Exemple #2
0
 public Card GetCard(int cardNum)
 {
     if (cardNum >= 0 && cardNum <= 51)
     {
         if ((cardNum == 51) && (LastCardDrawn != null))
         {
             LastCardDrawn(this);
         }
         return(cards[cardNum]);
     }
     else
     {
         throw new CardOutOfRangeException((Cards)cards.Clone() as Cards);
     }
     //throw (new System.ArgumentOutOfRangeException("cardNum", cardNum,
     //      "Value must be between 0 and 51."));
 }
Exemple #3
0
        public object Clone()
        {
            Deck newDeck = new Deck(cards.Clone() as Cards);

            return(newDeck);
        }