コード例 #1
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();
        }