Advertisement
Guest User

Untitled

a guest
May 29th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.43 KB | None | 0 0
  1.         static void BlackJack()
  2.         {
  3.             Deck d1 = new Deck();
  4.             BJHand playerHand = new BJHand();
  5.             BJHand dealerHand = new BJHand();
  6.             bool play = true;
  7.             d1.Shuffle();
  8.  
  9.             while (play)
  10.             {
  11.                 Console.Clear();
  12.                 bool dealerHit = true;
  13.                 for (int i = 0; i < 2; i++)
  14.                 {
  15.                     if (d1.IsEmpty())
  16.                     {
  17.                         d1.NewDeck();
  18.                         d1.Shuffle();
  19.                     }
  20.                     playerHand.Add(d1.Deal());
  21.                     if (d1.IsEmpty())
  22.                     {
  23.                         d1.NewDeck();
  24.                         d1.Shuffle();
  25.                     }
  26.                     dealerHand.Add(d1.Deal());
  27.                 }
  28.  
  29.                 Console.WriteLine("Dealer's face up card: " + dealerHand[0].ToString());
  30.                 Console.WriteLine("\nYour hand:\n" + playerHand.ToString());
  31.                 Console.Write("Your score: " + playerHand.Score);
  32.                 if (playerHand.SoftScore)
  33.                 {
  34.                     Console.Write(", Soft\n");
  35.                 }
  36.                 else
  37.                 {
  38.                     Console.Write("\n");
  39.                 }
  40.  
  41.                 if (playerHand.IsBlackJack)
  42.                 {
  43.                     Console.WriteLine("\nDealer's hand:\n" + dealerHand.ToString());
  44.                     Console.WriteLine("Dealer's score: " + dealerHand.Score);
  45.                     if (dealerHand.IsBlackJack)
  46.                     {
  47.                         Console.WriteLine("\nIt's a tie.");
  48.                         Console.Write("\nWould you like to play another hand? y/n: ");
  49.                         goto ans;
  50.                     }
  51.                     else
  52.                     {
  53.                         Console.WriteLine("\nYou have a Black Jack. You win!");
  54.                         Console.Write("\nWould you like to play another hand? y/n: ");
  55.                         goto ans;
  56.                     }
  57.                 }
  58.  
  59.                 Console.Write("\nWould you like to Hit or Stand? Press h to Hit, press S to Stand: ");
  60.                 hos: char hitOrStand = Console.ReadKey().KeyChar;
  61.                 if (hitOrStand == 'h')
  62.                 {
  63.                     if (d1.IsEmpty())
  64.                     {
  65.                         d1.NewDeck();
  66.                         d1.Shuffle();
  67.                     }
  68.                     playerHand.Add(d1.Deal());
  69.                     Console.WriteLine("\nYour hand:\n" + playerHand.ToString());
  70.                     Console.Write("Your score: " + playerHand.Score);
  71.                     if (playerHand.SoftScore)
  72.                     {
  73.                         Console.Write(", Soft\n");
  74.                     }
  75.                     else
  76.                     {
  77.                         Console.Write("\n");
  78.                     }
  79.  
  80.                     if (playerHand.IsBusted())
  81.                     {
  82.                         Console.WriteLine("\nYou busted! Dealer wins.");
  83.                         Console.Write("\nWould you like to play another hand? y/n: ");
  84.                         goto ans;
  85.                     }
  86.                     else
  87.                     {
  88.                         Console.Write("\nWould you like to Hit or Stand? Press h to Hit, press S to Stand: ");
  89.                         goto hos;
  90.                     }
  91.                 }
  92.                 else if (hitOrStand == 's')
  93.                 {
  94.                     goto dt;
  95.                 }
  96.                 else
  97.                 {
  98.                     Console.Write("\nPlease press either h or s: ");
  99.                     goto hos;
  100.                 }
  101.  
  102.                 dt: while (dealerHit)
  103.                 {
  104.                     if (dealerHand.Score < 17)
  105.                     {
  106.                         if (d1.IsEmpty())
  107.                         {
  108.                             d1.NewDeck();
  109.                             d1.Shuffle();
  110.                         }
  111.                         dealerHand.Add(d1.Deal());
  112.                     }
  113.                     else if (dealerHand.Score >= 17 && dealerHand.SoftScore)
  114.                     {
  115.                         if (d1.IsEmpty())
  116.                         {
  117.                             d1.NewDeck();
  118.                             d1.Shuffle();
  119.                         }
  120.                         dealerHand.Add(d1.Deal());
  121.                     }
  122.                     else
  123.                     {
  124.                         dealerHit = false;
  125.                     }
  126.                 }
  127.  
  128.                 Console.WriteLine("\nDealer's Hand:\n" + dealerHand.ToString());
  129.                 Console.WriteLine("Dealer's Score: " + dealerHand.Score);
  130.                 Console.WriteLine("\nYour Hand:\n" + playerHand.ToString());
  131.                 Console.WriteLine("Your Score: " + playerHand.Score);
  132.                 if (dealerHand.IsBusted())
  133.                 {
  134.                     Console.WriteLine("\nDealer busted. You win!");
  135.                     Console.Write("\nWould you like to play another hand? y/n: ");
  136.                     goto ans;
  137.                 }
  138.                 else if (dealerHand.Score > playerHand.Score)
  139.                 {
  140.                     Console.WriteLine("\nDealer wins.");
  141.                     Console.Write("\nWould you like to play another hand? y/n: ");
  142.                     goto ans;
  143.                 }
  144.                 else if (dealerHand.Score < playerHand.Score)
  145.                 {
  146.                     Console.WriteLine("\nYou win!");
  147.                     Console.Write("\nWould you like to play another hand? y/n: ");
  148.                     goto ans;
  149.                 }
  150.                 else
  151.                 {
  152.                     Console.WriteLine("\nIt's a tie.");
  153.                     Console.Write("\nWould you like to play another hand? y/n: ");
  154.                     goto ans;
  155.                 }
  156.  
  157.                 ans: char answer = Console.ReadKey().KeyChar;
  158.                 if (answer == 'y')
  159.                 {
  160.                     playerHand.DiscardAll();
  161.                     dealerHand.DiscardAll();
  162.                     continue;
  163.                 }
  164.                 else if (answer == 'n')
  165.                 {
  166.                     play = false;
  167.                 }
  168.                 else
  169.                 {
  170.                     Console.Write("\nPlease press either y/n: ");
  171.                     goto ans;
  172.                 }
  173.             }
  174.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement