Exemple #1
0
        private Outcome CalculateOutcome(PlayerHand playerHand, DealerHand dealerHand)
        {
            var player = playerHand.FinalValue;
            var dealer = dealerHand.FinalValue;

            if (dealerHand.IsBlackjack)
            {
                return(playerHand.IsBlackjack ? Outcome.Push : Outcome.Lose);
            }
            else if (dealerHand.IsBusted)
            {
                return(Outcome.Win);
            }
            else if (player > dealer)
            {
                return(Outcome.Win);
            }
            else if (player < dealer)
            {
                return(Outcome.Lose);
            }
            else
            {
                return(Outcome.Push);
            }
        }
Exemple #2
0
        private void FinishHand(PlayerHand playerHand, DealerHand dealerHand)
        {
            var outcome = CalculateOutcome(playerHand, dealerHand);

            if (outcome == Outcome.Win)
            {
                Console.WriteLine($"{playerHand.Player.Name}, you won!");
                playerHand.Win();
                dealerHand.Lose();
            }
            else if (outcome == Outcome.Lose)
            {
                Console.WriteLine($"{playerHand.Player.Name}, you lost.");
                playerHand.Lose();
                dealerHand.Win();
            }
            else
            {
                Console.WriteLine($"{playerHand.Player.Name}, you pushed.");
                playerHand.Push();
                dealerHand.Push();
            }

            Thread.Sleep(2000);

            dealerHand.Dealer.Sweep(DiscardTray, playerHand);

            Draw();
        }
Exemple #3
0
        private void PlayHand(DealerHand hand)
        {
            hand.IsTurnPending = false;
            Draw();

            if (HasActivePlayers)
            {
                while (hand.KeepPlaying)
                {
                    Dealer.Deal(Shoe, hand);
                    Draw();
                }
            }

            Thread.Sleep(2000);
        }
Exemple #4
0
 public void Reset()
 {
     Hand = new DealerHand(this);
 }
Exemple #5
0
 public Dealer()
 {
     Hand = new DealerHand(this);
 }