Exemple #1
0
 public bool PlayHand(DeckOfCards deck, bool busted)
 {
     string answer;
     HandValue = CalculateHandValue(Hand, NumOfCards);
     while (busted == false)
     {
         Console.WriteLine("\nHand:");
         ShowHand();
         answer = "";
         bool validInput = false;
         while (validInput == false)
         {
             try
             {
                 while (answer != "yes" && answer != "y" && answer != "no" && answer != "n")
                 {
                     Console.Write("\nWould you like to take a hit?\n(Currently sitting at {0})\n(y/n):  ", HandValue);
                     answer = Console.ReadLine();
                 }
                 validInput = true;
             }
             catch (FormatException e)
             {
                 Console.WriteLine(e.Message + "\nInvalid input, please try again.\n");
             }
             catch (Exception e)
             {
                 Console.WriteLine(e.Message + "\nUnknown Error.\n");
             }
         }
         if (answer == "yes" || answer == "y" || answer == "Yes")
         {
             Hand[NumOfCards] = deck.DealCard();
             NumOfCards++;
             HandValue = CalculateHandValue(Hand, NumOfCards);
             if (HandValue > 21)
                 busted = true;
         }
         else
             break;
     }
     if (busted == true)
     {
         Console.WriteLine("\nHand:");
         ShowHand();
         Console.WriteLine("Total is:  {0}\nBusted.", HandValue);
         return true;
     }
     else
         return false;
 }
Exemple #2
0
 // methods
 public bool PlayHand(DeckOfCards deck, bool busted)
 {
     HandValue = CalculateHandValue(Hand, NumOfCards);
     ShowHand();
     Console.WriteLine("Currently at: {0}", HandValue);
     while (busted == false && HandValue < 17)
     {
         Console.WriteLine("Must take a hit until 17 or greater.\n");
         Hand[NumOfCards] = deck.DealCard();
         NumOfCards++;
         HandValue = CalculateHandValue(Hand, NumOfCards);
         if (HandValue > 21)
             busted = true;
         ShowHand();
         Console.WriteLine("\nCurrently at: {0}", HandValue);
     }
     if (busted == true)
     {
         Console.WriteLine("\nHand:");
         ShowHand();
         Console.WriteLine("Total is:  {0}\nBusted.", HandValue);
         return true;
     }
     else
         return false;
 }