Esempio n. 1
0
        private static void GetPlayers(Dealer dealer)
        {
            Console.WriteLine("Welcome to BlackJack.");
            var doneWithPlayers = false;

            while (!doneWithPlayers)
            {
                Console.Write("Please Enter Name of Player: ");
                var name = Console.ReadLine();

                try
                {
                    dealer.AddPlayer(name);
                }

                catch (PlayerAlreadyExist)
                {
                    Console.WriteLine($"Player {name} is already in the game.");
                }

                catch (MaxPlayers)
                {
                    Console.WriteLine($"The table only seats 5 players.");
                    break;
                }

                doneWithPlayers = !DoYesNoPrompt("Is there another player (y/n)? ");
            }
        }
Esempio n. 2
0
        public void TestPlayerMoneyTotal()
        {
            var dealer = new Dealer();

            dealer.AddPlayer("Testing");
            dealer.AddPlayer("Testing 1");
            var total = dealer.GetPlayerMoneyTotal("Testing");

            Assert.AreEqual(200, total);
            total = dealer.GetPlayerMoneyTotal("Testing 1");
            Assert.AreEqual(200, total);

            dealer.SetPlayerMoneyTotal("Testing", 300);
            total = dealer.GetPlayerMoneyTotal("Testing");
            Assert.AreEqual(300, total);
            total = dealer.GetPlayerMoneyTotal("Testing 1");
            Assert.AreEqual(200, total);

            Assert.Throws <PlayerDoesNotExist>(() => dealer.SetPlayerMoneyTotal("Bad Player", 300));
        }
Esempio n. 3
0
        public void TestDealerPlay()
        {
            const string playerName = "Testing 1";
            var          dealer     = new Dealer();

            dealer.AddPlayer(playerName);
            dealer.StartHand();
            var cardCnt = dealer.PlayerCardCount(playerName);

            Assert.AreEqual(2, cardCnt);
            Assert.AreEqual(2, dealer.DealerCardCount());
            Assert.IsFalse(dealer.PlayerHandHeld(playerName));
        }
Esempio n. 4
0
        public void TestAddPlayer()
        {
            var dealer = new Dealer();

            dealer.AddPlayer("Testing");
            Assert.Throws <PlayerAlreadyExist>(() => dealer.AddPlayer("Testing"));
            dealer.AddPlayer("Testing 1");
            dealer.AddPlayer("Testing 2");
            dealer.AddPlayer("Testing 3");
            dealer.AddPlayer("Testing 4");
            Assert.Throws <MaxPlayers>(() => dealer.AddPlayer("Testing 5"));
        }