예제 #1
0
        // Split the deck into defined number of smaller decks
        public static Deck[] DivideDeck(Deck startingDeck, int deckDivisions)
        {
            // Initialize array of decks of length deckDivisions
            Deck[] decks         = new Deck[deckDivisions];
            int    divisionIndex = deckDivisions;

            // Initialize the correct number of decks
            for (int i = 0; i < deckDivisions; i++)
            {
                decks[i] = new Deck();
            }

            // Loop through each card in the starting deck and assign it to the correct new deck
            // This is better than just splitting the deck down the middle as it more closely simulates dealing cards
            while (startingDeck.GetCount() > 0)
            {
                Card card = startingDeck.GetCard();

                // Add card to the correct player's deck
                decks[divisionIndex - 1].AddCard(card);

                // Decrement the division index unless it hits 1, then reset
                if (divisionIndex == 1)
                {
                    divisionIndex = deckDivisions;
                }
                else
                {
                    divisionIndex--;
                }
            }

            return(decks);
        }
예제 #2
0
        // Draw a card from the deck if there are any cards left
        public Card DrawCard()
        {
            if (drawDeck.GetCount() > 0)
            {
                // If there are cards left in the draw deck, use them
                return(drawDeck.GetCard());
            }
            else if (scoreDeck.GetCount() > 0)
            {
                // If no cards left in the draw deck, convert score deck to draw deck
                Console.WriteLine("** Shuffling deck for {0}", name);
                scoreDeck.Shuffle();
                drawDeck  = scoreDeck;
                scoreDeck = new Deck();

                return(drawDeck.GetCard());
            }
            else
            {
                // If no more cards are left this player loses
                return(null);
            }
        }