Esempio n. 1
0
        public void GetCardsTest()
        {
            List <Card> cards = DeckService.GetCards();

            Assert.IsTrue(cards.Count() == 52);
            Assert.IsTrue(cards.Any(c => c.CardType == CardType.Club) && cards.Any(c => c.CardType == CardType.Diamond));
            //Asserting that we have a variety of 52.
        }
Esempio n. 2
0
        static void PlayGame(Dealer dealer, List <Player> players)
        {
            List <Card> cards = DeckService.GetCards();

            cards = DeckService.ShuffleCards(cards);
            //Dealer is dealt two cards, one is face up.
            Console.ForegroundColor = ConsoleColor.Cyan;
            DeckService.Deal(dealer, cards, 2, false); //Rule 3: Dealer dealt 2, one face down.
            string lineSeparator = "\n____________";

            Console.WriteLine($"{dealer.Name} score is: {DeckService.GetHandScore(dealer)}{lineSeparator}");
            bool isGameOver = false;

            while (!isGameOver)
            {
                int lowestTurnCount = Math.Min(dealer.TurnNumber, players.Min(p => p.TurnNumber));
                if (dealer.TurnNumber == lowestTurnCount && !dealer.IsBust && !dealer.IsStaying)
                {
                    //Dealer's turn
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    DeckService.PlayerTurnChange(dealer, cards, players.Max(p => p.CurrentScore));
                    Console.WriteLine($"{dealer.Name} score is: {DeckService.GetHandScore(dealer)}{lineSeparator}");
                }
                else if (players.Any(p => p.TurnNumber == lowestTurnCount && !p.IsStaying && !p.IsBust))
                {
                    //Player's turn
                    foreach (var player in players.Where(p => p.TurnNumber == lowestTurnCount && !p.IsStaying && !p.IsBust))
                    {
                        Console.ForegroundColor = ConsoleColor.White;
                        //One thing I wasn't sure about was the case where the dealer's total is lower but another players total is higher...
                        //I'm not sure if the player has to hit in that case.
                        DeckService.PlayerTurnChange(player, cards, dealer.CurrentScore); //Rule 4.
                        Console.WriteLine($"{player.Name} score is: {DeckService.GetHandScore(player)}{lineSeparator}");
                    }
                }
                else
                {
                    isGameOver = true;
                }
                if (!isGameOver && (dealer.IsBust) || (dealer.IsStaying && players.All(p => p.IsStaying)) || players.All(p => p.IsBust))
                {
                    isGameOver = true;
                }
            }
            TallyScores(dealer, players);
            PlayAgainPrompt(dealer, players);
        }