public static void Intro() { ASCII_Art.StartArt(); do { //Computer guesses a number and the human tries to guess it //Set a random number Random randomNum = new Random(); //Intro Text Console.WriteLine("Let's play James Silcott's - The Number Guessing Game!"); Console.WriteLine(); Console.WriteLine("First we need two numbers to guess between, like 0 and 100"); //Find the min number of the guess Console.WriteLine("Give a MINIMUM number for the computer to guess:"); int min1Number = Convert.ToInt32(Console.ReadLine()); //Find the max number of the guess Console.WriteLine("Give a MAXIMUM number for the computer to guess:"); int max1Number = Convert.ToInt32(Console.ReadLine()); //Create a variable to store a random number from the min and max values fromt he user input int number = randomNum.Next(min1Number, max1Number); //Create a starting point by declaring variable for the guessed number int guessedNum = 0; //Start the number counter to see how many guesses it takes int countHuman = 0; //Show min and max user input results Console.WriteLine($"The computer has guessed a number between {min1Number} and {max1Number}"); //While the random number doesn't equal the number the user guesses than do the following code while (number != guessedNum) { //increment the count number countHuman++; Console.WriteLine($"Type a number between {min1Number} and {max1Number}: "); //Assign the value of user input guessed number guessedNum = Convert.ToInt32(Console.ReadLine()); //If the guess is less than the actual random number picked than dot he following code if (guessedNum < number) { ASCII_Art.ThumbsUp(); Console.WriteLine("Too low, guess higher"); } //Else if the guess is higher than the actual random number than do the folowing code else if (guessedNum > number) { ASCII_Art.ThumbsDown(); Console.WriteLine("Too high, guess lower"); } //Else the number is guessed else { ASCII_Art.ThumbsUpMulti(); Console.WriteLine($"Correct, you guessed the number " + $"in {countHuman} guesses"); } } //Break Point to start the computer guess game Console.WriteLine("Press any key to continu[e] . . . "); var readKey = Console.ReadLine().ToUpper(); #region Easter if (readKey == "E") { MasterClasses.EasterEgg.EasterEggFound(); } #endregion //Human guesses number and computer tries to guess it Console.WriteLine("Now let's have the computer try to guess!"); //Find the min value Console.WriteLine("Give a MINIMUM number for the computer to guess between:"); int min2Number = Convert.ToInt32(Console.ReadLine()); //Find max value Console.WriteLine("Give a MAXIMUM number for the computer to guess between:"); int max2Number = Convert.ToInt32(Console.ReadLine()); //Get the actual number from the human Console.WriteLine($"What is the number for the computer to guess between {min2Number} and {max2Number}?"); int numGiven = Convert.ToInt32(Console.ReadLine()); //Intialize the counter to start the count of guess it takes for the computer int countComputer = 0; int guess = (max2Number + min2Number) / 2; Console.WriteLine($"Is the number: {guess}"); //If the computer guesses the number right away show: if (numGiven == guess) { ASCII_Art.ThumbsUpMulti(); Console.WriteLine($"Nice, the computer guessed the correct number: {numGiven} in 1 guess"); } else { //While the computer guess doesn't equal the humasns number do: while (guess != numGiven) { //Increament the counter countComputer++; //If human number is more than the computer guess if (numGiven > guess) { ASCII_Art.ThumbsUp(); Console.WriteLine("Too low, guess higher!"); min2Number = guess; guess = (max2Number + min2Number) / 2; } //Else the human number is less than the computer guess else if (numGiven < guess) { ASCII_Art.ThumbsDown(); Console.WriteLine("Too High, guess lower!"); max2Number = guess; guess = (max2Number + min2Number) / 2; } //Else it equals else { ASCII_Art.ThumbsUpMulti(); Console.WriteLine($"Correct, you guessed the number {numGiven}" + $"in {countComputer} guesses"); } //Show the guessed number Console.WriteLine($"Is the number: {guess}"); //add 1 to the max value everytime the guess is wrong max2Number = max2Number + 1; } //Show the reults Console.WriteLine($"Nice, the computer guessed the correct number: {numGiven} in {countComputer} guesses"); Console.WriteLine($"You took {countHuman} and the computer took {countComputer} to guess"); //See if the human had less guesses if (countHuman < countComputer) { ASCII_Art.ThumbsUpMulti(); Console.WriteLine("Nice, you win! You guessed the number in less guesses than the computer"); } //See if the computer had less guesses else if (countHuman > countComputer) { Console.WriteLine("Sorry, the computer won. It guessed the number in less guesses than you"); } //See if the human and computer guesses equal else { ASCII_Art.ThumbsUp(); Console.WriteLine("TIE! Wow, you and the computer guessed the number in the same amount of guesses"); ASCII_Art.ThumbsDown(); } } } //If the user says no they don't want to play again, then exit the program, else play again while (TryAgainMessage.TryAgain() == true); }
//Method to play game public static int keyResponse() { //Used for debugging Console.WriteLine("the MIN number is: " + minEggNum); Console.WriteLine("the MAX number is: " + maxEggNum); Console.WriteLine("the middle number is: " + newMaxNumEgg); Console.WriteLine("the number to pick is: " + cpuEggNum); //Get the arrow key input var key = Console.ReadKey().Key; //If the guess is the first guess if (counter == 0) { Console.WriteLine($"THAT'S AMAZING! You guessed it in {counter + 1} guesses!"); } else { //Show how many guesses it took Console.WriteLine($"Congrats you guessed it in {counter + 1} guesses!"); } //This will allow the user to play the Easter Egg again Console.WriteLine("Press any key to continu[e] . . . "); var readKey = Console.ReadLine().ToUpper(); if (readKey == "E") { EasterEggFound(); } //If statement on which arrow key is used //UP ARROW if (key == ConsoleKey.UpArrow) { Console.WriteLine("You Selected: HIGHER"); //If the middle range number is LESS than the actual number if (newMaxNumEgg < cpuEggNum) { ASCII_Art.ThumbsUp(); Console.WriteLine("Correct, it is higher!"); //Reset the MIN value to the middle range minEggNum = newMaxNumEgg; //reset the middle range to be another middle range of dividing the range again newMaxNumEgg = ((maxEggNum - newMaxNumEgg) / 2) + minEggNum; } //If the middle range number is MORE than the actual number else { Console.WriteLine("Wrong, it was lower"); } Console.WriteLine("Do you think it is HIGHER or LOWER than " + newMaxNumEgg); //return the new middle range number return(newMaxNumEgg); } //DOWN ARROW else { Console.WriteLine("You Selected: LOWER"); //If the middle range number is MORE than the actual number if (newMaxNumEgg > cpuEggNum) { ASCII_Art.ThumbsDown(); Console.WriteLine("Correct, it is lower!"); //Reset the MAX value to the middle range maxEggNum = newMaxNumEgg; } else { Console.WriteLine("Wrong, it was higher"); } //reset the middle range to be another middle range of dividing the range again newMaxNumEgg = ((maxEggNum - minEggNum) / 2) + minEggNum; Console.WriteLine("Do you think it is HIGHER or LOWER than " + newMaxNumEgg); //return the new middle range number return(newMaxNumEgg); } }