示例#1
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WindowHeight    = 40;
            Console.WindowWidth     = 90;
            Console.OutputEncoding  = System.Text.Encoding.UTF8;
            Game.ShowTitle();

            // Create the player and deal
            Player player1 = new Player();
            Player dealer  = new Player();

            // Create the deck
            Deck deck = new Deck();

            // Variables that will be used during game
            Game           game;
            bool           playAgain;
            ConsoleKeyInfo cki;

            do
            {
                // Initilize a new game with the player, dealer, and deck
                game = new Game(player1, dealer, deck);

                // Prompt the user for Y/N to continue playing
                while (true)
                {
                    Console.WriteLine("-------------------------------");
                    Console.Write("\nPlay again? (Y/N) ");
                    cki = Console.ReadKey();
                    Console.WriteLine("\n-------------------------------");
                    Console.WriteLine("\n");

                    if (cki.Key == ConsoleKey.Y)
                    {
                        playAgain = true;
                        break;
                    }
                    else if (cki.Key == ConsoleKey.N)
                    {
                        playAgain = false;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Invalid selection.");
                    }
                }

                Console.Clear();
            } while (playAgain);

            Console.WriteLine("\n   GAMES WON\n" +
                              "   =======================\n" +
                              "   Player: {0}\n" +
                              "   Dealer: {1}\n" +
                              "\n   Press any key to exit...", player1.wins, dealer.wins);
            Console.ReadKey();
        }