Example #1
0
        private void FindTheWinner()
        {
            var humanPlayers = _humanPlayers.Where(player => player.GetScore() < 22)
                               .OrderByDescending(player => player.GetScore());
            var highestScoringHuman = humanPlayers.FirstOrDefault();
            var computerScore       = _computer.GetScore();


            if (highestScoringHuman != null && (highestScoringHuman.GetScore() > computerScore && computerScore > 0 ||
                                                computerScore > 21))
            {
                highestScoringHuman.Communicate($"You won! Woooohooooo ohhh yeah {highestScoringHuman.GetName()}");
            }

            if (highestScoringHuman != null && (highestScoringHuman.GetScore() < computerScore && computerScore <= 21) || _humanPlayers.All(player => player.GetScore() > 22))
            {
                _computer.Communicate($"{_computer.GetName()} wins!");
            }
        }
Example #2
0
        private void PlayUntilBustOrStay(PlayerHand playerHand)
        {
            DealInitialCards(playerHand);
            var playerChoice = playerHand.ChooseHitOrStay();

            while (CanContinuePlay(playerHand, playerChoice))
            {
                ContinuePlay(playerHand);

                if (IsThereABust(playerHand))
                {
                    playerHand.Communicate($"{playerHand.GetName()} lost.");
                    playerHand.Communicate("It's a bust!");
                    break;
                }

                playerChoice = playerHand.ChooseHitOrStay();
            }
        }