Esempio n. 1
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);
        }
Esempio n. 2
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));
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Obtains the certain number of cards starting at the desired index
        /// </summary>
        public void ObtainCards()
        {
            nextCardIndex = 0;
            int startingRank;   // the index to start at

            // if cards exist, clear them
            if (dealerCards.Count > 0 || dealerCards != null)
            {
                dealerCards.Clear();
            }

            // determine the starting index
            if (numberOfCards == DECK_SIZES[0])
            {
                startingRank = (int)CardRank.Ten;
            }
            else if (numberOfCards == DECK_SIZES[1])
            {
                startingRank = (int)CardRank.Six;
            }
            else
            {
                startingRank = (int)CardRank.Deuce;
            }

            // obtain the certain number of cards
            for (int suitCount = 0; suitCount < 4; suitCount++)
            {
                for (int rankCount = startingRank; rankCount < 15; rankCount++)
                {
                    dealerCards.Add(new Card((CardRank)rankCount, (CardSuit)suitCount));
                }
            }

            Shuffle();  // shuffles the cards
        }