Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void Play()
        {
            Console.WriteLine("Starting War!");
            GetPlayersNames();
            while (deck.GetCount() >= 2)
            {
                p1c = deck.RemoveCard();
                p2c = deck.RemoveCard();
                AnnounceCardDraws(p1, p2, p1c, p2c);

                if (CompareCards(p1c, p2c))
                {
                    p1.Wins += 1;
                    AnnounceRoundWinner(p1);
                }
                else
                {
                    p2.Wins += 1;
                    AnnounceRoundWinner(p2);
                }
            }

            DeclareWinner(p1, p2);
        }
Exemplo n.º 3
0
 // Return the current total number of cards in player's control
 public int GetScore()
 {
     return(drawDeck.GetCount() + scoreDeck.GetCount());
 }