Esempio n. 1
0
        // Constructor that initialises Contents with the specified number of card decks.
        public Deck(int numberOfDecks)
        {
            Contents      = new IndexedLinkedList <Card>();
            TotalDeckSize = 0;
            rng           = new Random();

            Add(numberOfDecks);
        }
Esempio n. 2
0
        /// <summary>
        /// Helper method that creates and returns a single deck of cards.
        /// </summary>
        /// <returns>
        /// Returns the deck of cards as an IndexedLinkedList<Node<Card>>.
        /// </returns>
        private IndexedLinkedList <Card> CreateDeck()
        {
            IndexedLinkedList <Card> singleDeck = new IndexedLinkedList <Card>();

            for (int i = 2; i < (int)Ranks.Ace + 1; i++)
            {
                for (int j = 0; j < (int)Suits.Spades + 1; j++)
                {
                    singleDeck.AddLast(new Card((Suits)j, (Ranks)i));
                }
            }

            return(singleDeck);
        }
Esempio n. 3
0
        /// <summary>
        /// Helper method that joins the main deck and additional specified subdeck together.
        /// </summary>
        /// <param name="subDeck">
        /// The subdeck to be added to the main deck.
        /// </param>
        private void JoinDeck(IndexedLinkedList <Card> subDeck)
        {
            // Check to prevent exceptions.
            if (TotalDeckSize == 0)
            {
                Contents.Head = subDeck.Head;
                Contents.Tail = subDeck.Tail;

                Contents.Count += subDeck.Count;
                TotalDeckSize  += subDeck.Count;
            }
            else
            {
                Contents.Tail.Next    = subDeck.Head;
                subDeck.Head.Previous = Contents.Tail;
                Contents.Tail         = subDeck.Tail;

                Contents.Count += subDeck.Count;
                TotalDeckSize  += subDeck.Count;
            }
        }