Exemple #1
0
        private const int MAX_GUESS = 10; // Maximum range for shift guesses

        // Description: Tests all public functionality of the EncryptWord class
        // Preconditions: None
        // Postconditions: None
        public void RunTests()
        {
            Console.WriteLine("Starting tests...");
            Console.WriteLine("TEST 1");
            EncryptWord test1 = new EncryptWord();

            Console.WriteLine("Encrypted word [error]: "
                              + test1.EncodeWord("Tes"));
            Console.WriteLine("Decrypted word [error]: " + test1.DecodeWord());
            test1.ResetEverything();
            Console.WriteLine("Encrypted word: " + test1.EncodeWord("Test 1"));
            Console.WriteLine(test1.GetGuessStatistics());
            GuessAllValues(test1);
            Console.WriteLine(test1.GetGuessStatistics());
            Console.WriteLine("Decrypted word [Test 1]: " + test1.DecodeWord());

            Console.WriteLine("\nTEST 2");
            EncryptWord test2 = new EncryptWord("Hello, World!");

            Console.WriteLine(test2.GetGuessStatistics());
            GuessAllValues(test2);
            Console.WriteLine(test2.GetGuessStatistics());
            Console.WriteLine("Decrypted word [Hello, World!]: "
                              + test2.DecodeWord());

            Console.WriteLine("\nTESTING COMPLETE");
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
Exemple #2
0
 // Description: Helper function to iterate through guesses for
 //      an EncryptWord object's shift value
 // Preconditions: EncryptWord object must be on (word has been
 //      encrypted in the class)
 // Postconditions: None
 private void GuessAllValues(EncryptWord test)
 {
     for (int i = MIN_GUESS; i < MAX_GUESS; i++)
     {
         Console.WriteLine("Guess [" + i + "]: "
                           + test.GuessTheShiftValue(i));
     }
 }
Exemple #3
0
        static void Main(string[] args)
        {
            EncryptWord e1 = new EncryptWord();
            EncryptWord e2 = new EncryptWord();

            const int ARRAY_SIZE = 8;

            string[] testArray = new string[ARRAY_SIZE];

            Main m = new Main();

            m.CreateArray(testArray);

            // Introduction to game
            Console.WriteLine(
                "--------- Welcome to GUESS THAT SHIFTY NUMBER game!---------");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(
                "Each letter of the scrambled word is right-shifted by a certain ");
            Console.WriteLine(
                "number of letters. The number could be 1 through 5. You have to ");
            Console.WriteLine(
                "guess how many shifts happened to that word! Example: \'cjuf\' ");
            Console.WriteLine(
                "(encrypted) is actually \'bite\' (solved) shifted by 1. The answer is 1.");
            Console.WriteLine(
                "Let's Play!!");


            m.PlayGame(e1, testArray, ARRAY_SIZE); // tests entire array on 1st EW object

            Console.WriteLine("But let's try again, improve your score!");
            Console.WriteLine();

            m.PlayGame(e2, testArray, ARRAY_SIZE); // tests entire array on 2nd EW object (but with different shifts)


            // Goodbye message
            Console.WriteLine("Thank you for playing GUESS THAT SHIFTY NUMBER!!");
        }
Exemple #4
0
        public void PlayGame(EncryptWord e, string[] testArray, int size)
        {
            string encryptedWord = e.Encrypt(testArray, ref indexArr);

            // Asks user to guess the number
            Console.WriteLine("What number was this word shifted by?");
            Console.WriteLine(encryptedWord);

            int  number       = GetUserGuess();
            bool isRightGuess = e.Guess(number);

            // checks if number is right guess
            while (!isRightGuess)
            {
                if (number > size)
                {
                    Console.WriteLine("Enter a number between 1 and 5.");
                }
                else if (number < size)
                {
                    Console.WriteLine("You guessed: " + number);
                    Console.WriteLine("Nope, try again!");
                }

                number       = GetUserGuess();
                isRightGuess = e.Guess(number);
            }

            // when guess is correct
            Console.WriteLine("You guessed: " + number);
            Console.WriteLine("THAT'S CORRECT!!");
            Console.WriteLine("Decrypted word: " + e.Decrypt());
            Console.WriteLine();

            Console.WriteLine(e.PrintStats(numberOfGames));  // print user stats to console

            // stops game if end of array
            const int GAME_OVER = 7;

            if (numberOfGames == GAME_OVER)
            {
                // reset variables for 2nd EW object
                numberOfGames = 1;
                indexArr      = 0;

                Console.WriteLine("All out of games!");
                return;
            }

            Console.WriteLine("Play again? Type 'y' for yes, 'n' for no.");

            string replayAnswer = Console.ReadLine();

            while (replayAnswer != "y" && replayAnswer != "n")
            {
                if (replayAnswer.Length > 1)
                {
                    Console.WriteLine("Enter only 1 character: 'y' for yes or 'n' no.");
                }
                else
                {
                    Console.WriteLine("Enter 'y' for yes, or 'n' for no.");
                }

                replayAnswer = Console.ReadLine();
            }

            Console.WriteLine(); // formatting

            if (replayAnswer == "y")
            {
                numberOfGames++; // next game begins
                e.reset();       // resets most EncryptWord class variables

                while (Console.KeyAvailable)
                {
                    Console.ReadKey(true);
                }
                //// reset cin
                //cin.clear();
                //cin.ignore(std::numeric_limits < std::streamsize >::max(), '\n');

                PlayGame(e, testArray, size);
            }
        }