Beispiel #1
0
        public void AcesFirstTwoCards(Player player, Dealer dealer)
        {
            if (player.PlayerHand[0].Name == "A" && player.PlayerHand[1].Name == "A")
            {
                Ace.ReplaceAceValue(player);
            }

            if (dealer.PlayerHand[0].Name == "A" && dealer.PlayerHand[1].Name == "A")
            {
                Ace.ReplaceAceValue(dealer);
            }
        }
Beispiel #2
0
        public bool didBustToSeventeen(Dealer dealer, Deck deck)
        {
            while (dealer.SumCardValues() <= 16)
            {
                deck.PlayerDraw(dealer);
            }

            if (Ace.IsAceInHand(dealer) && dealer.SumCardValues() > 21)
            {
                Ace.ReplaceAceValue(dealer);
                didBustToSeventeen(dealer, deck);
            }

            if (dealer.SumCardValues() > 21)
            {
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        public static int GameRound(Player player, Dealer dealer, Deck deck)
        {
            if (player.PlayerHand.Count == 0 || dealer.PlayerHand.Count == 0)
            {
                deck.FreshDeal(player, dealer);

                //If the first two draws are Aces, it prevents busting with a 22.
                deck.AcesFirstTwoCards(player, dealer);
            }

            Console.WriteLine($"Dealer's Cards: [{dealer.PlayerHand[0].Name}] [Hidden]");
            Console.Write("Player's Cards: ");

            foreach (Cards card in player.PlayerHand)
            {
                Console.Write($"[{card.Name}] ");
            }

            Console.WriteLine($"Total: {player.SumCardValues()}");


            if (player.SumCardValues() == 21)
            {
                Console.WriteLine("BLACKJACK! You won!!");
                player.RoundScore += 1;
                return(0);
            }

            if (player.SumCardValues() > 21)
            {
                Console.WriteLine($"BUST! You lost with a total of {player.SumCardValues()}..");
                dealer.RoundScore += 1;
                return(0);
            }

            Console.Write("Stay or Hit? (Enter 'S' or 'H'): ");


            char input = Game.CollectValidInput("Stay or Hit");

            if (input == 'S')
            {
                if (dealer.didBustToSeventeen(dealer, deck) == true)
                {
                    player.RoundScore += 1;
                    dealer.WonOrLossOutput("dealerBust", dealer);
                    return(0);
                }
                else
                {
                    string outcome = Game.CompareHands(player, dealer);
                    dealer.WonOrLossOutput(outcome, dealer);
                }
            }

            if (input == 'H')
            {
                Console.Clear();
                deck.PlayerDraw(player);

                if (player.SumCardValues() > 21 && Ace.IsAceInHand(player))
                {
                    Ace.ReplaceAceValue(player);
                    GameRound(player, dealer, deck);
                }
                else
                {
                    GameRound(player, dealer, deck);
                }
            }

            return(0);
        }