Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void BlackJack()
- {
- Deck d1 = new Deck();
- BJHand playerHand = new BJHand();
- BJHand dealerHand = new BJHand();
- bool play = true;
- d1.Shuffle();
- while (play)
- {
- Console.Clear();
- bool dealerHit = true;
- for (int i = 0; i < 2; i++)
- {
- if (d1.IsEmpty())
- {
- d1.NewDeck();
- d1.Shuffle();
- }
- playerHand.Add(d1.Deal());
- if (d1.IsEmpty())
- {
- d1.NewDeck();
- d1.Shuffle();
- }
- dealerHand.Add(d1.Deal());
- }
- Console.WriteLine("Dealer's face up card: " + dealerHand[0].ToString());
- Console.WriteLine("\nYour hand:\n" + playerHand.ToString());
- Console.Write("Your score: " + playerHand.Score);
- if (playerHand.SoftScore)
- {
- Console.Write(", Soft\n");
- }
- else
- {
- Console.Write("\n");
- }
- if (playerHand.IsBlackJack)
- {
- Console.WriteLine("\nDealer's hand:\n" + dealerHand.ToString());
- Console.WriteLine("Dealer's score: " + dealerHand.Score);
- if (dealerHand.IsBlackJack)
- {
- Console.WriteLine("\nIt's a tie.");
- Console.Write("\nWould you like to play another hand? y/n: ");
- goto ans;
- }
- else
- {
- Console.WriteLine("\nYou have a Black Jack. You win!");
- Console.Write("\nWould you like to play another hand? y/n: ");
- goto ans;
- }
- }
- Console.Write("\nWould you like to Hit or Stand? Press h to Hit, press S to Stand: ");
- hos: char hitOrStand = Console.ReadKey().KeyChar;
- if (hitOrStand == 'h')
- {
- if (d1.IsEmpty())
- {
- d1.NewDeck();
- d1.Shuffle();
- }
- playerHand.Add(d1.Deal());
- Console.WriteLine("\nYour hand:\n" + playerHand.ToString());
- Console.Write("Your score: " + playerHand.Score);
- if (playerHand.SoftScore)
- {
- Console.Write(", Soft\n");
- }
- else
- {
- Console.Write("\n");
- }
- if (playerHand.IsBusted())
- {
- Console.WriteLine("\nYou busted! Dealer wins.");
- Console.Write("\nWould you like to play another hand? y/n: ");
- goto ans;
- }
- else
- {
- Console.Write("\nWould you like to Hit or Stand? Press h to Hit, press S to Stand: ");
- goto hos;
- }
- }
- else if (hitOrStand == 's')
- {
- goto dt;
- }
- else
- {
- Console.Write("\nPlease press either h or s: ");
- goto hos;
- }
- dt: while (dealerHit)
- {
- if (dealerHand.Score < 17)
- {
- if (d1.IsEmpty())
- {
- d1.NewDeck();
- d1.Shuffle();
- }
- dealerHand.Add(d1.Deal());
- }
- else if (dealerHand.Score >= 17 && dealerHand.SoftScore)
- {
- if (d1.IsEmpty())
- {
- d1.NewDeck();
- d1.Shuffle();
- }
- dealerHand.Add(d1.Deal());
- }
- else
- {
- dealerHit = false;
- }
- }
- Console.WriteLine("\nDealer's Hand:\n" + dealerHand.ToString());
- Console.WriteLine("Dealer's Score: " + dealerHand.Score);
- Console.WriteLine("\nYour Hand:\n" + playerHand.ToString());
- Console.WriteLine("Your Score: " + playerHand.Score);
- if (dealerHand.IsBusted())
- {
- Console.WriteLine("\nDealer busted. You win!");
- Console.Write("\nWould you like to play another hand? y/n: ");
- goto ans;
- }
- else if (dealerHand.Score > playerHand.Score)
- {
- Console.WriteLine("\nDealer wins.");
- Console.Write("\nWould you like to play another hand? y/n: ");
- goto ans;
- }
- else if (dealerHand.Score < playerHand.Score)
- {
- Console.WriteLine("\nYou win!");
- Console.Write("\nWould you like to play another hand? y/n: ");
- goto ans;
- }
- else
- {
- Console.WriteLine("\nIt's a tie.");
- Console.Write("\nWould you like to play another hand? y/n: ");
- goto ans;
- }
- ans: char answer = Console.ReadKey().KeyChar;
- if (answer == 'y')
- {
- playerHand.DiscardAll();
- dealerHand.DiscardAll();
- continue;
- }
- else if (answer == 'n')
- {
- play = false;
- }
- else
- {
- Console.Write("\nPlease press either y/n: ");
- goto ans;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement