//Executes a unit test of class Deck.
        static void testDeck()
        {
            //Creates a deck and prints out the first 20 cards dealt.
            Console.WriteLine("\nTest Deck (prints first 20 cards):");
            Deck deck = new Deck();
            for (int i = 0; i < 20; i++)
            {
                Card newcard = deck.deal();
                Console.WriteLine(newcard.ToString());
            }
            Console.WriteLine();

            //Test the acceptDiscards method, and print out the discard pile.
            Hand newHand = new Hand();
            for (int i = 0; i < 3; i++)
            {
                newHand.add(deck.deal());
            }
            deck.acceptDiscards(newHand.surrenderCards());
            Console.WriteLine("Test collecting cards from players (prints 0 if the hand is empty and received)");
            if (newHand.ToString().CompareTo("") == 0)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine("ERROR.");
            }
            Console.WriteLine("(The above cards were sucsessfully dealt, and recieved by the dealer, and added to the discard pile.)");
        }
        //Excecutes a unit test of class Deck.
        static void testDeck()
        {
            //Creates a deck and prints out the first 20 cards dealt.
              Console.WriteLine("\nTest Deck:");
              Deck deck = new Deck();
              for (int i = 0; i < 20; i++)
              {
              Card newcard = deck.deal();
              Console.WriteLine(newcard.ToString());
              }
              Console.WriteLine();

              //Test the collectCardsFromPlayers method, and print out the discard pile.
              Hand newHand = new Hand();
              for (int i = 0; i < 3; i++)
              {
              newHand.add(deck.deal());
              }
              deck.collectCardsFromPlayers(newHand.giveCardsBackToDealer());
              Console.WriteLine("Test collecting cards from players/adding cards to discard pile: ");
              foreach (Card c in deck.discardPile)
              {
              Console.WriteLine(c.ToString());
              }
              Console.WriteLine("(The above cards were sucsessfully dealt, and recieved by the dealer, and added to the discard pile.)");
        }
        /// <summary>
        /// Runs unit tests for the Android class.
        /// </summary>
        static void TestAndroid()
        {
            Hand h = new Hand();
            Console.WriteLine("Tests for the Android class:\n");
            Android c3po = new Android("c3po", h);
            //Console.WriteLine("Output Window with 'c3po' as banner should have popped up."); //Not applicable in Blackjack3
            Deck d = new Deck();

            //Test getCard() and showHand().
            c3po.getsCard(d.deal());
            c3po.getsCard(d.deal());
            Console.WriteLine("Current Hand after having been dealt two cards: \n");
            h = c3po.showHand();
            Console.WriteLine(h.ToString());

            //Tests outcomeOfRound()
            Console.WriteLine("Test a win by pressing enter.");
            Console.ReadLine();
            c3po.outcomeOfRound(Outcome.Win);
            Console.WriteLine("Sucsess.");

            //Tests wantsCard()
            Console.WriteLine("Test wantsCard() by pressing enter.");
            Console.ReadLine();
            c3po.wantsCard();
            Console.WriteLine("Success.\n");
        }
Example #4
0
 static void testDeck() {
     Console.WriteLine("test deck------");
     Deck d1 = new Deck();
     for (int i = 0; i <10; i++) {
         Console.WriteLine("Deck has {0}", d1.deal().ToString()); 
     }
 }
Example #5
0
 static void testHand() {
     Console.WriteLine("test hand------");
     Deck d2 = new Deck();
     Hand h1 = new Hand();
     for (int i = 0; i < 5; i++) {
         h1.add(d2.deal());
     }
     Console.WriteLine(h1);
 }
        /// <summary>
        /// This method handles the guest players turn, prompting them for more cards, and doing 
        /// basic error handling should there be invalid input. It will return immediatly should the 
        /// guest player reach 21. It determines whether or not the player busted.
        /// </summary>
        /// <param name="guestHand">The guest's hand.</param>
        /// <param name="houseHand">The house players hand.</param>
        /// <param name="d">The deck in play for the current game session.</param>
        public static void guestTurn(Hand guestHand, Hand houseHand, Deck d)
        {
            Console.Write("Do you want another card (y or n)? ");
            string answer = Console.ReadLine();
            if (answer.CompareTo("y") != 0 && answer.CompareTo("n") != 0)
            {
                Console.WriteLine("Invalid Input, please type 'y' or 'n'.");
                guestTurn(guestHand, houseHand, d);
            }
            else
            {
                if (answer.CompareTo("y") == 0)
                {
                    guestHand.add(d.deal());
                    Console.WriteLine("Your hand is: ");
                    Console.Write(guestHand.ToString());
                    Console.WriteLine("The score is: " + guestHand.BJscore());

                    if (guestHand.BJscore() == 21)
                    {
                        Console.WriteLine();
                        return;
                    }
                    else if (guestHand.BJscore() > 21)
                    {
                        Console.WriteLine("A bust!\n\nYou lose!");
                        playersGiveTheirCardsBack(guestHand, houseHand, d);
                        printStats();
                        anotherRound();
                        guestBusted = true;
                    }
                    else
                    {
                        guestTurn(guestHand, houseHand, d);
                    }
                }
                else
                {
                    Console.WriteLine();
                }
            }
        }
        //Executes a unit test of class Hand.
        static void testHand()
        {
            Console.WriteLine("\nTest Hand:");
            Deck deck = new Deck();
            Hand currentHand = new Hand();

            for (int i = 0; i < 2; i++)
            {
                currentHand.add(deck.deal());
            }
            Console.WriteLine(currentHand.ToString());

            //Test the hand score.
            Console.WriteLine("\nTest Hand Score:");
            Console.WriteLine(currentHand.BJscore());

            //Test for giving cards back to dealer.
            Console.WriteLine("\nTest Giving cards to dealer (end of round action): ");
            foreach (Card c in currentHand.surrenderCards())
            {
                Console.WriteLine(c.ToString());
            }
            Console.WriteLine("(The above cards have been sucsessfully returned to the dealer.)");
        }
        /// <summary>
        /// A method containing commands necessary to complete one round of blackjack.
        /// This method, along with the methods that it calls, determine the win/loss/tie
        /// state of the player.
        /// </summary>
        /// <param name="d">The deck being used for the current game.</param>
        public static void RoundOfBlackjack(Deck d)
        {
            //A new round begins. Neither player has busted, as no cards have been dealt.
            Console.WriteLine("\nNew Round:");
            round++;
            guestBusted = false;
            houseBusted = false;

            //Creates Hands for the guest and the member of the house.
            Hand guestHand = new Hand();
            Hand houseHand = new Hand();

            //Each Player is dealt two cards from the deck into their hands.
            guestHand.add(d.deal());
            guestHand.add(d.deal());
            houseHand.add(d.deal());
            houseHand.add(d.deal());

            //Reveal the top cards of each player.
            Console.WriteLine("Your top card is: " + guestHand.firstCardDealt().ToString());
            Console.WriteLine("The house player's top card is: " + houseHand.firstCardDealt().ToString());

            //Check to see if the house player was dealt a blackjack.
            if (houseHand.BJscore() == 21)
            {
                Console.WriteLine("The house player holds a blackjack! The round is over.\n");
                Console.WriteLine("You lose!");
                Console.WriteLine("After " + round + " rounds, you have " + wins + " wins.");
                playersGiveTheirCardsBack(guestHand, houseHand, d);
                anotherRound();
                return;
            }
            else
            {
                Console.WriteLine("The house player does NOT hold a blackjack, so play continues:\n");
            }

            //Look at the player's hand.
            Console.WriteLine("Your hand is:");
            Console.Write(guestHand.ToString());
            Console.WriteLine("The score is: " + guestHand.BJscore());

            //Check to see if the player was dealt blackjack...
            if (guestHand.BJscore() == 21)
            {
                Console.WriteLine("Wowzers! You were dealt blackjack, lucky you!\nYou win!\n");
                playersGiveTheirCardsBack(guestHand, houseHand, d);
                wins++;
                printStats();
                anotherRound();
                return;
            }

            //At this point, neither player has gotten blackjack. Thus cards are now dealt out
            //to the guest player at theier discretion. The round ends if the human player busts.
            guestTurn(guestHand, houseHand, d);
            if (guestBusted == true)
            {
                return;
            }

            //Once the human player is done, the computerized "house" hand will aquire cards. Will end the round if the computer busts.
            housesTurn(houseHand, guestHand, d);
            if (houseBusted == true)
            {
                return;
            }

            //Check for a tie.
            if (guestHand.BJscore() == houseHand.BJscore())
            {
                Console.WriteLine("\nThe round ends in a tie!");
                playersGiveTheirCardsBack(guestHand, houseHand, d);
                printStats();
                anotherRound();
            }
            //Otherwise, check for a win.
            else if (guestHand.BJscore() > houseHand.BJscore())
            {
                Console.WriteLine("\nYou Win!");
                playersGiveTheirCardsBack(guestHand ,houseHand, d);
                wins++;
                printStats();
                anotherRound();
            }
            //Otherwise check for a loss.
            else
            {
                Console.WriteLine("\nYou Lose!");
                printStats();
                playersGiveTheirCardsBack(guestHand, houseHand, d);
                anotherRound();
            }
        }
        /// <summary>
        /// This method handles the house player's turn (which occurs after the guest player's turn).
        /// The house player will continue to accept cards if the current value of the hand is less
        /// than 17. It will keep track of whether or not the house player busts.
        /// </summary>
        /// <param name="houseHand">The house player's hand.</param>
        /// <param name="guestHand">The guest player's hand.</param>
        /// <param name="d">The deck in play for the current play session.</param>
        public static void housesTurn(Hand houseHand, Hand guestHand, Deck d)
        {
            while (houseHand.BJscore() <= 21)
            {
                Console.WriteLine("The house player's hand is: ");
                Console.WriteLine(houseHand.ToString() + "The score is " + houseHand.BJscore());

                if (houseHand.BJscore() < 17)
                {
                    houseHand.add(d.deal());
                }
                else
                {
                    return;
                }
            }
            Console.WriteLine("The house player's hand is: ");
            Console.WriteLine(houseHand.ToString() + "The score is " + houseHand.BJscore());
            Console.WriteLine("A bust!\n\nYou win!");
            playersGiveTheirCardsBack(guestHand, houseHand, d);
            wins++;
            printStats();
            anotherRound();
            houseBusted = true;
        }
        //Excecutes a unit test of class Hand.
        static void testHand()
        {
            Console.WriteLine("\nTest Hand:");
              Deck deck = new Deck();
              Hand currentHand = new Hand();

              for (int i = 0; i < 2; i++)
              {
              currentHand.add(deck.deal());
              }
              Console.WriteLine(currentHand.ToString());

              //Test the hand score.

              Console.WriteLine("\nTest Hand Score:");
              Console.WriteLine(currentHand.BJscore());

              //Test for the first card Dealt.
              Console.WriteLine("\nTest first card dealt:");
              Console.WriteLine(currentHand.firstCardDealt().ToString());

              //Test for giving cards back to dealer.
              Console.WriteLine("\nTest Giving cards to dealer (end of round action): ");
              foreach (Card c in currentHand.giveCardsBackToDealer())
              {
              Console.WriteLine(c.ToString());
              }
              Console.WriteLine("(The above cards have been sucsessfully returned to the dealer.)");

              //NO TEST FOR THE REMOVE METHOD, AS IT IS NOT USED IN MY PROGRAM
        }
        /// <summary>
        /// Runs unit tests for the Human class.
        /// </summary>
        static void TestHuman()
        {
            Hand h = new Hand();
            Console.WriteLine("Tests for the Human class:\n");
            Human Christian = new Human("Christian", h);
            //Console.WriteLine("Output Window with 'Christian' as banner should have popped up."); //Not Applicable in Blackjack3
            Deck d = new Deck();

            //Test getCard() and showHand().
            Christian.getsCard(d.deal());
            Christian.getsCard(d.deal());
            Console.WriteLine("Current Hand after having been dealt two cards: \n");
            h = Christian.showHand();
            Console.WriteLine(h.ToString());

            //Tests outcomeOfRound()
            Console.WriteLine("Test a win by pressing enter.");
            Console.ReadLine();
            Christian.outcomeOfRound(Outcome.Win);
            Console.WriteLine("Sucsess.");

            //Tests wantsCard() NOT USED IN Blackjack3
            Console.WriteLine("Test wantsCard() by pressing enter.");
            Console.ReadLine();
            Christian.wantsCard();
            Console.WriteLine("Success.\n");
        }