Esempio n. 1
0
        /// <summary>
        /// Clones the collection of cards.
        /// </summary>
        /// <returns>A <see cref="CardList"/>.</returns>
        public virtual object Clone()
        {
            var result = new CardList();

            foreach (var card in this)
            {
                result.Add((Card)card.Clone());
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Deals the top card from the current instance to the specified instance.
        /// </summary>
        /// <param name="cards">Specifies the destination for the dealt card.</param>
        /// <returns>The <see cref="Card"/> that was dealt.</returns>
        public Card DealTo(CardList cards)
        {
            if (this.Count < 1)
            {
                throw new InvalidOperationException("There are no cards to deal.");
            }

            var result = this[0];

            cards.Add(result);
            this.RemoveAt(0);

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the specified number of standard 52 card decks.
        /// </summary>
        /// <param name="numberOfDecks">The number of decks to create.</param>
        /// <returns>The deck of cards.</returns>
        public static CardList CreateDecks(int numberOfDecks = 1)
        {
            var cardSuits = (CardSuit[])Enum.GetValues(typeof(CardSuit));
            var cardFaces = (CardFace[])Enum.GetValues(typeof(CardFace));
            var result    = new CardList(numberOfDecks * cardSuits.Length * cardFaces.Length);

            for (int i = 0; i < numberOfDecks; i++)
            {
                foreach (var suit in cardSuits)
                {
                    foreach (var face in cardFaces)
                    {
                        result.Add(new Card(suit, face));
                    }
                }
            }

            return(result);
        }