Example #1
0
        /**<summary>Method PrepareGame creates an ordered deck, a dealer, a player, a bot player and instructs
         * the dealer to deal cards to the player</summary>
         */
        private void PrepareGame()
        {
            CreateDeck();
            var dealer = new Dealer(_deck, new BasicShuffler(new BasicRandomGenerator()));

            AssignDealerToTable(dealer);
            var player = new Player();

            dealer.DealCardToPlayer(player, InitialNoOfCards);
            var bot = new BotPlayer();

            dealer.DealCardToPlayer(bot, InitialNoOfCards);
            GamePlay(dealer, player, bot);
        }
Example #2
0
        /**
         * <summary>GamePlay is the main flow of the game. It instructs what the dealer should do and
         * calls utility classes InputValidator and ValueCalculator to check at points in the game</summary>
         */
        private void GamePlay(Dealer dealer, Player player, BotPlayer bot)
        {
            var table = dealer.GetTable();

            //While player has not won or busted
            while (player.PlayerScoreUnder21())
            {
                var playerScore = ValueCalculator.HandWorth(player.GetHand()); //Get the player's current score
                player.ReceiveScore(playerScore);
                Table.AnnounceScore(player, true);                             //Print to console

                if (player.PlayerScoreIs21())
                {
                    break;
                }

                if (player.PlayerScoreUnder21())
                {
                    var hitOrStay = dealer.AskHitOrStay();
                    if (hitOrStay == 1) // Hit = 1
                    {
                        dealer.DealCardToPlayer(player, 1);
                        table.AnnounceDrawnCard(player, true);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (player.PlayerScoreIs21())
            {
                table.CongratulationsBlackJack();
            }
            else if (!player.PlayerScoreUnder21())
            {
                table.Busted();
            }
            else
            {
                //If player chose to stay, then bot player must face the player
                DealerPlaysWithBotDealer(dealer, bot, player);
            }
            //Ask to reset the game at the end
            Program.ResetGame();
        }