/// <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; }
/// <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]; } }
/// <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); }
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)); } } }