Exemple #1
0
        public void Play()
        {
            bool continuePlay = true;

            Screen.SplashScreen();
            Screen.PromptPlayerName();

            var player = new Player(Console.ReadLine());

            var dealerComputer = new Player();

            deck = new Deck();

            while (continuePlay)
            {
                // Initialize screen and reset player and dealer's certain property
                // for the new round.
                Console.Clear();
                player.ResetPlayerHand();
                dealerComputer.ResetPlayerHand();

                // Create a new deck if remaining cards are less than 20
                if (deck.GetRemainingDeckCount() < 20)
                {
                    deck = new Deck();
                }

                deck.ShowRemainingDeckCount();

                // Show player bank roll
                Console.WriteLine($"{player.Name} Chips Balance: {player.ChipsOnHand}");

                if (player.ChipsOnHand <= 10)
                {
                    Utility.WriteLineInColor("Insufficient chips in your account.", ConsoleColor.Red);
                    Utility.WriteLineInColor("Please reload your chips from the counter to continue to play.\n", ConsoleColor.Red);

                    continuePlay = false;
                    break;
                }

                // Get bet amount from player
                Console.Write("Enter chips: ");
                player.ChipsOnBet = Convert.ToInt16(Console.ReadLine());
                // for brevity, no input validation here.

                // Deal first two cards to player (Background)
                deck.DrawCard(player);
                deck.DrawCard(player);

                // Show player's hand (UI)
                player.ShowUpCards();
                Utility.Sleep();

                Utility.Line();

                // Deal first two cards to dealer (Background)
                deck.DrawCard(dealerComputer);
                deck.DrawCard(dealerComputer);

                // Show dealer's hand (UI)
                dealerComputer.ShowUpCards(true);
                Utility.Sleep();

                Utility.Line();

                // Check natural black jack
                if (CheckNaturalBlackJack(player, dealerComputer) == false)
                {
                    // If both also don't have natural black jack,
                    // then player's turn to continue.
                    // After player's turn, it will be dealer's turn.
                    TakeAction(player);
                    TakeAction(dealerComputer, player.IsBusted);

                    AnnounceWinnerForTheRound(player, dealerComputer);
                }

                Console.WriteLine("This round is over.");

                Console.Write("\nPlay again? Y or N? ");

                continuePlay = Console.ReadLine().ToUpper() == "Y" ? true : false;
                // for brevity, no input validation
            }

            PrintEndGame(player, dealerComputer);
        }