Exemple #1
0
        public static void RunInteractiveTest()
        {
            Console.Write ("\n\nRunning Interactive Test Console...\n" + CardGame.ConsoleLine('~') + "\n");

            CardGame currentGame = new BlackjackGame();
            //DojoCardGame currentGame = new PokerGame();
            //DojoCardGame currentGame = new SpadesGame();
            //DojoCardGame currentGame = new HeartsGame();

            bool playAgain = true;

            Console.WriteLine ("Press enter to play " + currentGame.Name + "...");
            Console.Read ();        //< Function waits for the user to input a character.

            Debug.WriteLine ("\n\n" + CardGame.ConsoleLine('#') + "Starting a game of " + currentGame.Name);

            /** Play-again loop.
                A play-again loop goes in a loop where the user is asked if they want to play again. The user can
                enter "hit", "hold", "exit", or "quit". The code for the game */
            while (playAgain && currentGame.PlayGameInConsole ())    // Main game loop.
            {
                Console.WriteLine ("Do you want to play again?\n" +
                        "Type yes to continue, or no to quit.");

                bool inputValid = false;

                while (!inputValid)
                {
                    String input = Console.ReadLine ().ToLower ();

                    /* If the user wants to continue, they need to type the letter y, or else we need to exit the program
                       loop.
                        We need to convert the input to lower case letters just in case someone capitalizes any of the
                        letters.
                    */
                    if (input == "yes")     //  Keep playing.
                    {
                        // playAgain is current true.
                        inputValid = true;
                    }
                    else if (input == "no") //< Then exit the play-again loop.
                    {
                        playAgain = false;
                        inputValid = true;
                    }
                    else
                    {
                        Console.Write ("\nPlease type yes to continue, or no to quit.\n");
                    }
                }
            }
        }