コード例 #1
0
ファイル: Player.cs プロジェクト: PonyoHuesers/.NET-BlackJack
        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);
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: PonyoHuesers/.NET-BlackJack
        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);
        }