예제 #1
0
        /// <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();
            }
        }
예제 #2
0
        //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
        }