public Result Deal() { var result = Result.Continue; // default result // on first load, deck is null - shuffle if (Deck.Cards == null) { Deck.Shuffle(); } if (Deck.Cards.Count < 4) { Deck.Shuffle(); Dealer.ShowCards(); result = Result.Shuffling; } else { Player.NewHand(Deck.Deal(), Deck.Deal()); Dealer.NewHand(Deck.Deal(), Deck.Deal()); Dealer.Hand.HideHoleCard = true; NeedsDeal = false; } if (Player.Hand.HasBlackJack && Dealer.Hand.HasBlackJack) { Update(); Dealer.ShowCards(); result = Result.DoubleBlackJack; } else if (Player.Hand.HasBlackJack) { Update(); result = Result.PlayerBlackJack; } else if (Dealer.Hand.HasBlackJack) { Update(); Dealer.ShowCards(); result = Result.DealerBlackJack; } Save(); return(result); }
public void NewGame() { Deck deck = new Deck(); deck.Initalize(1); Dealer.NewHand(); Player.NewHand(); Console.Clear(); Console.OutputEncoding = System.Text.Encoding.UTF8; Console.WriteLine(GetLogo()); Console.WriteLine(); Console.WriteLine($"Player Money: ${Player.Money}.00"); Console.WriteLine(); int bet = PlayerBet(); Console.WriteLine(); Dealer.AddCard(deck.DrawCard()); Dealer.AddCard(deck.DrawCard()); Player.AddCard(deck.DrawCard()); Player.AddCard(deck.DrawCard()); bool playerWon = false; bool playerDone = false; // Player action! while (!playerDone) { Console.WriteLine("************************************************************************************"); Console.WriteLine("== Dealer Cards =="); Console.WriteLine(PrintCards(Dealer.Hand, true)); Console.WriteLine(); Console.WriteLine("== Player Cards =="); Console.WriteLine(PrintCards(Player.Hand, false)); Console.WriteLine(); if (Player.Hand.BestTotal() == 21) { Console.WriteLine("You got blackjack, you won!"); bet = (int)((double)bet * 1.5); playerWon = true; playerDone = true; break; } if (Player.Hand.BestTotal() > 21) { Console.WriteLine("You busted, you lost!"); playerWon = false; playerDone = true; break; } // H = false // S = true playerDone = PlayerAction(Player, deck); } bool dealerDone = false; while (playerWon == false && dealerDone == false && Player.Hand.BestTotal() < 21) { Console.WriteLine("Dealer's Turn!"); Console.WriteLine("************************************************************************************"); Console.WriteLine("== Dealer Cards =="); Console.WriteLine(PrintCards(Dealer.Hand, false)); Console.WriteLine(); Console.WriteLine("== Player Cards =="); Console.WriteLine(PrintCards(Player.Hand, false)); Console.WriteLine(); if (Dealer.Hand.BestTotal() > 21) { Console.WriteLine("The dealer has busted, the player won!"); dealerDone = true; playerWon = true; } else if ((Dealer.Hand.BestTotal() == 17 && Dealer.Hand.IsSoft) || Dealer.Hand.BestTotal() < 17) { Console.WriteLine("Dealer must hit on 16 and less or soft 17!"); Dealer.Hand.AddCard(deck.DrawCard()); dealerDone = false; Console.WriteLine("Press any button for the Dealer to draw!"); Console.ReadLine(); } else { dealerDone = true; Console.WriteLine(); if (Dealer.Hand.BestTotal() > Player.Hand.BestTotal()) { Console.WriteLine("The dealer won!"); } else if (Dealer.Hand.BestTotal() < Player.Hand.BestTotal()) { Console.WriteLine("The player won!"); } else { Console.WriteLine("Push - there is no winner!"); } } } if (playerWon) { Player.Money += bet; } if (!playerWon && Dealer.Hand.BestTotal() != Player.Hand.BestTotal()) { Player.Money -= bet; } Console.WriteLine($"Player Money: ${Player.Money}.00"); Console.WriteLine(); Console.WriteLine("The hand is over, press any button to play again!"); Console.ReadLine(); }