Esempio n. 1
0
        // This is the method where the computer guesses, no magic numbers here, can accept any Int32 valid input
        internal static void CompGuess(int min, int max)
        {
            lastCurrent = 0;
            numGuesses  = 0;
            current     = (max - min) / 2;
            Console.Clear();
            ConsoleMenuPainter.TextColor(15, 1);
            Console.WriteLine($"\nThe computer guesses your number from {min} to {max}\n");
            ConsoleMenuPainter.TextColor();
            Console.WriteLine("Enter your whole number (I am not going to use this to guess, only to lock in your number.");
            Console.Write("I would NEVER think *you* would try to trick or cheat, but some would): ");
            userNum = Elicit.WholeNumber(min, max);
            low     = min;
            high    = max;
            bool finished = false;

            do
            {
                BisectionSplit(max);
                finished = IsThisYourNumber();
            } while (!finished);
            Console.WriteLine("\n\n");
            ConsoleMenuPainter.TextColor(15, 1);
            Console.Write($"Your number was {current}, it took {numGuesses} times to guess it.");
            ConsoleMenuPainter.TextColor();
            Console.Write("\nHit any key to go to the start menu");
            Console.ReadKey();
        }
Esempio n. 2
0
        // This gets the user defined values for the user to guess between
        internal static void UserValuesHumanGuess()
        {
            Console.Clear();
            ConsoleMenuPainter.TextColor(15, 1);
            Console.WriteLine("You enter the limit numbers, computer picks and you guess");
            ConsoleMenuPainter.TextColor();
            Console.Write("\nEnter the lower: ");
            int min = Elicit.WholeNumber(int.MinValue + 2, int.MaxValue - 1);

            Console.Write("\nEnter the upper number: ");
            int max = Elicit.WholeNumber(min + 1, int.MaxValue);

            HumanGuesses(min, max);
        }
Esempio n. 3
0
        // This gets user defined values for the computer to guess between
        internal static void UserValues()
        {
            Console.Clear();
            ConsoleMenuPainter.TextColor(15, 1);
            Console.WriteLine("The computer guesses your number from values you define");
            ConsoleMenuPainter.TextColor();
            Console.Write("\nEnter the lower: ");
            int min = Elicit.WholeNumber(int.MinValue + 2, int.MaxValue - 1);

            Console.Write("\nEnter the upper number: ");
            int max = Elicit.WholeNumber(min + 1, int.MaxValue);

            CompGuess(min, max);
        }
Esempio n. 4
0
        // Business logic of the user guessing what the number is
        internal static void HumanGuesses(int low, int high)
        {
            Random rand    = new Random();
            int    compNum = rand.Next(low, high + 1);
            bool   done    = false;

            numGuesses = 0;

            Console.Clear();
            ConsoleMenuPainter.TextColor(15, 1);
            Console.WriteLine($"\nYou guess the computer's number from {low} to {high}");
            ConsoleMenuPainter.TextColor();
            Console.WriteLine($"OK, I have guessed my number from {low} to {high}!");

            do
            {
                Console.Write($"Whole numbers from {low} to {high}, what is your guess: ");
                userNum = Elicit.WholeNumber(low, high);
                numGuesses++;
                Console.WriteLine();
                if (userNum == compNum)
                {
                    ConsoleMenuPainter.TextColor(15, 1);
                    Console.WriteLine($"Good guess! My number was {compNum}.");
                    Console.WriteLine($"You got it in {numGuesses} guesses.");
                    ConsoleMenuPainter.TextColor();
                    Console.WriteLine("Hit any key to continue back to the main menu.");
                    Console.ReadKey();
                    done = true;
                }
                if (userNum > compNum)
                {
                    Console.WriteLine($"Your guess of {userNum} was too high");
                }
                if (userNum < compNum)
                {
                    Console.WriteLine($"Your guess of {userNum} was too low");
                }
            } while (!done);
        }