コード例 #1
0
        public void TestPlayersCardsAreNotUnique()
        {
            CardValidator cardValidator       = new CardValidator();
            string        testCardCollection1 = "2h 6d as 4s 3h";
            string        testCardCollection2 = "2h 6c ac 4c 3c";

            string errorMessage = string.Empty;
            //build the first string first
            bool test1 = cardValidator.IsValid(testCardCollection1, out errorMessage);
            //build the second string second
            bool test2 = cardValidator.IsValid(testCardCollection2, out errorMessage);

            Assert.IsFalse(test2);
        }
コード例 #2
0
        public void TestCurrentCardFiveIsNotUnique()
        {
            CardValidator cardValidator      = new CardValidator();
            string        testCardCollection = "2h 6d as 3h 3h";
            string        errorMessage       = string.Empty;

            Assert.IsFalse(cardValidator.IsValid(testCardCollection, out errorMessage));
        }
コード例 #3
0
        public void TestNoCardInput()
        {
            CardValidator cardValidator      = new CardValidator();
            string        testCardCollection = " ";
            string        errorMessage       = string.Empty;

            Assert.IsFalse(cardValidator.IsValid(testCardCollection, out errorMessage));
        }
コード例 #4
0
        public void TestCardCollectionHasNoSpace()
        {
            CardValidator cardValidator      = new CardValidator();
            string        testCardCollection = "2h6das4s3h";
            string        errorMessage       = string.Empty;

            Assert.IsFalse(cardValidator.IsValid(testCardCollection, out errorMessage));
        }
コード例 #5
0
        public void TestHasFewerThanFiveCards()
        {
            CardValidator cardValidator      = new CardValidator();
            string        testCardCollection = "2h 6d as 4s";
            string        errorMessage       = string.Empty;

            Assert.IsFalse(cardValidator.IsValid(testCardCollection, out errorMessage));
        }
コード例 #6
0
        public void TestHasInvalidFormatCards()
        {
            CardValidator cardValidator      = new CardValidator();
            string        testCardCollection = "2h 6J as 4s 3jdka";
            string        errorMessage       = string.Empty;

            Assert.IsFalse(cardValidator.IsValid(testCardCollection, out errorMessage));
        }
コード例 #7
0
        public void TestHasMoreThanFiveValidCards()
        {
            CardValidator cardValidator      = new CardValidator();
            string        testCardCollection = "2h 6d as 4s 3h ah 9d";
            string        errorMessage       = string.Empty;

            Assert.IsTrue(cardValidator.IsValid(testCardCollection, out errorMessage));
        }
コード例 #8
0
        static void Main(string[] args)
        {
            CardValidator cardValidator          = new CardValidator();
            PokerGame     pokerGame              = new PokerGame();
            bool          isTerminated           = false;
            int           currentNumberOfPlayers = 0;

            ShowIntroductions();
            while (!isTerminated)
            {
                Console.Write("\nEnter the player name: ");
                string playerName = Console.ReadLine();
                string playerCard = string.Empty;
                DeclarePlayerCard(playerName, ref playerCard);
                while (cardValidator.IsValid(playerCard, out string errorMessage) != true)
                {
                    Console.WriteLine("Error: {0}\n", errorMessage);
                    DeclarePlayerCard(playerName, ref playerCard);
                }
                pokerGame.AddPlayer(playerName, playerCard);
                currentNumberOfPlayers++;
                if (currentNumberOfPlayers > 1)
                {
                    Console.WriteLine("\nPress ANY KEY to add more players or ESC to start\n");
                    if (Console.ReadKey(true).Key == ConsoleKey.Escape)
                    {
                        isTerminated = true;
                    }
                }
            }
            pokerGame.StartGame();
            Console.WriteLine("-------Results-------");
            for (int i = 0; i < pokerGame.NumberOfPlayers; i++)
            {
                Console.WriteLine("{0}: {1} ({2})", pokerGame.GetPlayerName(i),
                                  pokerGame.GetCardCollection(i), pokerGame.GetPlayerHand(i));
            }
            Console.WriteLine("\n-------Winner/s-------");
            for (int i = 0; i < pokerGame.GetWinners().Count; i++)
            {
                Console.WriteLine(pokerGame.GetWinners()[i]);
            }
            Console.WriteLine("\nPress ANY KEY to exit");
            Console.ReadLine();
        }
コード例 #9
0
ファイル: CreditCard.cs プロジェクト: vglinca/Lessons
 public bool IsValid()
 {
     return(_validationStrategy.IsValid(this));
 }