static void Main(string[] args) { Deck d = new Deck(); while (true) { Clear(); Hand hand = new Hand(); Dealer dealer = new Dealer(); hand.startHand = d.DrawTwoFromDeck(); bool Bust = false; bool Stick = false; bool BlackJack = false; WriteLine(d.TwoCardHandToString(hand.startHand)); WriteLine(d.CheckBlackJack(hand.startHand)); WriteLine(); WriteLine("H to hit, S to stick."); for (int i = 0; i < 3; i++) { WriteLine(); switch (ReadKey().Key) { case ConsoleKey.H: Write("it"); WriteLine(); Card newCard = d.DrawFromDeck(); hand.extraCards[i] = newCard; WriteLine($"{newCard}, {d.handCount(hand.startHand, hand.extraCards)}"); if(d.handCount(hand.startHand, hand.extraCards) > 21) Bust = true; if (d.handCount(hand.startHand, hand.extraCards) == 21) BlackJack = true; break; case ConsoleKey.S: Write("tick."); WriteLine(); Stick = true; break; default: Write(" is an Invalid key."); WriteLine(); break; } if (d.CardsInDeck == 0) { //no more cards. } if (Bust) { WriteLine("Bust."); ReadKey(); break; } if (Stick || BlackJack || i == 2) { WriteLine(); WriteLine("DEALER."); dealer.DealerstartHand = d.DrawTwoFromDeck(); WriteLine(d.TwoCardHandToString(dealer.DealerstartHand)); WriteLine(d.CheckBlackJack(dealer.DealerstartHand)); for (int o = 0; o < 3; o++) { if (d.handCount(dealer.DealerstartHand, dealer.DealerextraCards) > 21) { WriteLine("Bust."); break; } if (d.handCount(dealer.DealerstartHand, dealer.DealerextraCards) == 21) { WriteLine("Stick."); break; } if (dealer.ShouldDraw(d.handCount(dealer.DealerstartHand, dealer.DealerextraCards))) { Card newCard = d.DrawFromDeck(); dealer.DealerextraCards[o] = newCard; WriteLine($"{newCard}, {d.handCount(dealer.DealerstartHand, dealer.DealerextraCards)}"); } else { WriteLine("Stick."); break; } if (o == 2) { WriteLine("Stick."); } } WriteLine(); WriteLine(d.Winner(hand, dealer)); ReadKey(); break; } } } }
public string Winner(Hand Player, Dealer Dealer) { int playerTotal = handCount(Player.startHand, Player.extraCards); int dealerTotal = handCount(Dealer.DealerstartHand, Dealer.DealerextraCards); if (playerTotal > 21 && dealerTotal > 21) { if (dealerTotal == playerTotal) return $"Draw both players has bust! Player has {playerTotal}. Dealer has {dealerTotal}"; } if ((dealerTotal < playerTotal) || (dealerTotal > 21 && playerTotal < 22)) return $"Player Winners with {playerTotal}. Dealer has {dealerTotal}"; if ((dealerTotal > playerTotal) || (playerTotal > 21 && dealerTotal < 22)) return $"Dealer Winners with {dealerTotal}. Player has {playerTotal}"; return $"Draw! Player has {playerTotal}. Dealer has {dealerTotal}"; }