Exemple #1
0
        // description: Allows the user to guess what the current shift value is.
        // input: The value the user thinks the letters have shifted by.
        // processing: Compares the user's guess to the current shift value. Depending
        //				on the answer, the appropriate statistics are incremented,
        //				and the user is told if their guess was wrong or right.
        //				If the user guessed correctly, the game will automatically
        //				switch into the OFF state, and reset the Caesar Shift number.
        //				If the user did not guess correctly, the appropriate message
        //				is displayed. In the case of invalid input, the appropriate
        //				message will be dislpayed out.
        //output: Depends on the users, input. Either an error message or a correct guess
        //        from winning the round.
        private void guessShiftNum(int guess)
        {
            //Check the shift-state
            if (!game.checkShiftState())
            {
                game.resetShift();
            }

            //Check if guess is correct or not
            bool correct = game.guessShift(guess);

            if (correct)
            {
                Console.WriteLine("You guessed correctly!");
                Console.WriteLine("The Caesar Shift value has been " +
                                  "automatically reset for you");
                Console.WriteLine("and your statistics have " +
                                  "been updated!");
                Console.WriteLine("You can check them with the " +
                                  "'stats' command.");
            }
            else
            {
                Console.WriteLine("Sorry, you guessed incorrectly");
            }
        }
Exemple #2
0
        // description: This method is used for testing purposes. It will run through
        //				all of the EncryptWord functions, testing them out. The result
        //				should be the same as playing the game yourself. This is just to
        //				save some time.
        // input: none
        // processing: Will proccess through all of the EncryptWord functions to test
        //				them out.
        // output: Any output included in the other functions will be included in this
        //			function as well.
        public void testEncryptWord()
        {
            const int SHIFT_MAX = 11;

            Console.WriteLine("Welcome to EncryptWord Test! This process is " +
                              "automated, no input is required.");
            Console.WriteLine("Now starting a new game, Test Game 1...");
            EncryptWord testGame1 = new EncryptWord();

            Console.WriteLine("New game created...");
            Console.WriteLine("The current stats should be at 0...");
            string testStats = testGame1.printStats();

            Console.WriteLine(testStats);

            string word1 = "Rhino", word2 = "LaRRy";
            string word3 = "ECLIPSE", word4 = "Egyptian";

            Console.WriteLine("Now testing the encrypt function...");
            Console.WriteLine("Inputting valid inputs...");
            Console.WriteLine("Inputting the word " + word1 + "...");
            Console.WriteLine("Encrypted " + word1 + " is " +
                              testGame1.encryptInput(word1));
            Console.WriteLine("Decoded: " + testGame1.decode());
            Console.WriteLine("Inputting the word " + word2 + "...");
            Console.WriteLine("Encrypted " + word2 + " is " +
                              testGame1.encryptInput(word2));
            Console.WriteLine("Decoded: " + testGame1.decode());
            Console.WriteLine("Inputting the word " + word3 + "...");
            Console.WriteLine("Encrypted " + word3 + " is " +
                              testGame1.encryptInput(word3));
            Console.WriteLine("Decoded: " + testGame1.decode());
            Console.WriteLine("Inputting the word " + word4 + "...");
            Console.WriteLine("Encrypted " + word4 + " is " +
                              testGame1.encryptInput(word4));
            Console.WriteLine("Decoded: " +
                              testGame1.decode());

            testStats = testGame1.printStats();
            Console.WriteLine("Current stats so far: " + testStats);

            Console.WriteLine("Attempting to guess the shift, " +
                              "will loop until correct...");
            for (int i = 0; i < SHIFT_MAX; i++)
            {
                if (testGame1.guessShift(i))
                {
                    Console.WriteLine(i + " is correct!");
                }
                else
                {
                    Console.WriteLine(i + " was not correct");
                }
            }

            testStats = testGame1.printStats();
            Console.WriteLine("Current stats so far: " + testStats);
            Console.WriteLine("You can still play the user-input " +
                              "version of the game.");
            Console.WriteLine("Use 'help' for a list of commands.");
        }