Exemple #1
0
        public void DealTest()
        {
            List <Card> testCards = new List <Card>();

            testCards.Add(new Card(CardType.Diamond, new CardWorth(new KeyValuePair <string, int?>("Five", 5)), true));
            testCards.Add(new Card(CardType.Club, new CardWorth(new KeyValuePair <string, int?>("Six", 6)), true));
            DeckService.Deal(player1, testCards, 2, true);
            Assert.IsTrue(player1.Hand.Count() == 2);
            Assert.IsTrue(testCards.Count() == 0);
            //Asserting that the player was dealt two, and that we removed the two from the deck.
        }
Exemple #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);
        }