예제 #1
0
        public static void Exit()
        {
            while (true)
            {
                SmileEmoji.Emoji();
                Console.WriteLine();
                Console.Write("Are you sure you want to exit? Type: 1)No or 2)Yes: ");
                string response = Console.ReadLine();
                int    answer;
                bool   x = int.TryParse((response), out answer);

                Console.WriteLine();
                if (!x)
                {
                    Console.WriteLine("Only number 1 or 2 is accepted");
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                    Console.WriteLine("Press Enter...");
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ReadLine();
                    Console.Clear();
                }
                else if (answer < 1 || answer > 2)
                {
                    Console.WriteLine("Choices involve only number 1 or number 2");
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                    Console.WriteLine("Press Enter...");
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ReadLine();
                    Console.Clear();
                }
                else if (answer == 1)
                {
                    Console.Clear();
                    Console.WriteLine();
                    Console.WriteLine("Okay returning back to The Number Game...");
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                    Console.WriteLine("Press Enter");
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ReadLine();
                    Console.Clear();
                    return;
                }
                else if (answer == 2)
                {
                    Console.Clear();
                    Console.WriteLine();
                    SmileEmoji.Emoji();
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Thanks for PLaying the Number Game! GoodBye");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.ReadLine();

                    Environment.Exit(0);
                }
            }
        }
예제 #2
0
        public static void NumberGuessRange()
        {
            SmileEmoji.Emoji();

            //Make an array to display previous guesses

            ValidGuess[] previousGuesses = new ValidGuess[10];

            for (int index = 0; index < previousGuesses.Length; index++)
            {
                previousGuesses[index] = new ValidGuess();
            }

            //Initiate a guess count

            int counter = 9;

            //Give user intructions on game

            Welcome(counter);
            Console.ReadKey();
            Console.Clear();
            SmileEmoji.Emoji();
            Welcome(counter);
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine("                                                |-------------|");
            Console.WriteLine("                                                |---       ---|");
            Console.WriteLine("                                                |---Level 5---|");
            Console.WriteLine("                                                |---       ---|");
            Console.WriteLine("                                                |-------------|");
            Console.ForegroundColor = ConsoleColor.White;
            Console.BackgroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine("                                             Press any key to continue                                                  ");
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ReadKey();
            Console.Clear();

            //Create a random number for the user to guess

            Random rr = new Random();
            int    RR = (rr.Next(1, 151));

            //Make scenario options according to user input and loop until out of guesses

            while (counter > 0)
            {
                Console.WriteLine();
                Console.BackgroundColor = ConsoleColor.DarkMagenta;
                Console.WriteLine("You have " + counter + " guesses");
                Console.BackgroundColor = ConsoleColor.Black;
                PrintGuesses(previousGuesses);
                Console.WriteLine();
                Console.Write("Pick a ");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("WHOLE ");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("number between 1-150 inclusively, or type 1000 to exit: ");
                string guess = Console.ReadLine();
                Console.Clear();

                bool x = float.TryParse((guess), out float number);

                if (!x)
                {
                    Console.WriteLine();
                    Console.WriteLine("You can only enter a number between 1-150 inclusively, answer is a WHOLE number");

                    continue;
                }
                else if (number == 1000)
                {
                    Console.Clear();
                    ExitOption.Exit();
                }
                else if (number == RR)
                {
                    SmileEmoji.Emoji();
                    Console.WriteLine();
                    previousGuesses[counter].Guess = number;
                    previousGuesses[counter].Color = "You got it";
                    counter--;
                    PrintGuesses(previousGuesses);
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine("You got the secret number!");
                    ContinueKey();
                    Console.ReadKey();
                    Console.Clear();
                    SmileEmoji.Emoji();
                    PrintGuesses(previousGuesses);
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.DarkMagenta;
                    Console.WriteLine("The secret number is " + RR);
                    Console.BackgroundColor = ConsoleColor.Black;
                    ContinueKey();
                    Console.ReadKey();
                    Console.Clear();
                    SmileEmoji.Emoji();
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                    Console.WriteLine("...Moving up to the next level!!...");
                    Console.BackgroundColor = ConsoleColor.Black;
                    ContinueKey();
                    Console.ReadKey();
                    Console.Clear();
                    return;
                }
                else if (number == RR - 6 && number < 151 && number > 0)
                {
                    CheckingForRepeatedLowGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    VeryCloseTooLow(number);
                }
                else if (number == RR - 5 && number < 151 && number > 0)
                {
                    CheckingForRepeatedLowGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    VeryCloseTooLow(number);
                }
                else if (number == RR - 4 && number < 151 && number > 0)
                {
                    CheckingForRepeatedLowGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    VeryCloseTooLow(number);
                }
                else if (number == RR - 3 && number < 151 && number > 0)
                {
                    CheckingForRepeatedLowGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    SuperCLoseTooLow(number);
                }
                else if (number == RR - 2 && number < 151 && number > 0)
                {
                    CheckingForRepeatedLowGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    SuperCLoseTooLow(number);
                }
                else if (number == RR - 1 && number < 151 && number > 0)
                {
                    CheckingForRepeatedLowGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    SuperCLoseTooLow(number);
                }
                else if (number == RR + 6 && number < 151 && number > 0)
                {
                    CheckingForRepeatedHighGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    VeryCloseTooHigh(number);
                }
                else if (number == RR + 5 && number < 151 && number > 0)
                {
                    CheckingForRepeatedHighGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    VeryCloseTooHigh(number);
                }
                else if (number == RR + 4 && number < 151 && number > 0)
                {
                    CheckingForRepeatedHighGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    VeryCloseTooHigh(number);
                }
                else if (number == RR + 3 && number < 151 && number > 0)
                {
                    CheckingForRepeatedHighGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    SuperCloseTooHigh(number);
                }
                else if (number == RR + 2 && number < 151 && number > 0)
                {
                    CheckingForRepeatedHighGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    SuperCloseTooHigh(number);
                }
                else if (number == RR + 1 && number < 151 && number > 0)
                {
                    CheckingForRepeatedHighGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    SuperCloseTooHigh(number);
                }
                else if (number > 150)
                {
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(number + " :Too high, remember the answer is a Whole number between 1-150 inclusively only");
                    Console.ForegroundColor = ConsoleColor.White;

                    continue;
                }
                else if (number < 1)
                {
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(number + " :Too Low, remember the answer is a Whole number between 1-150 inclusively only");
                    Console.ForegroundColor = ConsoleColor.White;

                    continue;
                }
                else if (number % 1 != 0)
                {
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(number + ": Remember the answer is going to be a Whole number");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else if (number < RR)
                {
                    CheckingForRepeatedLowGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(number + " :Too Low!");
                    Console.ForegroundColor = ConsoleColor.White;

                    continue;
                }
                else if (number > RR)
                {
                    CheckingForRepeatedHighGuesses(ref previousGuesses, number, ref counter);
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(number + " :Too High!");
                    Console.ForegroundColor = ConsoleColor.White;

                    continue;
                }
            }

            //Create an outro if the user runs out of guesses

            PrintGuesses(previousGuesses);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Sorry you have ran all out of guesses");
            ContinueKey();
            Console.ReadKey();
            Console.Clear();
            PrintGuesses(previousGuesses);
            Console.WriteLine();
            Console.WriteLine();
            Console.BackgroundColor = ConsoleColor.DarkMagenta;
            Console.WriteLine("The secret number was " + RR);
            Console.BackgroundColor = ConsoleColor.Black;
            ContinueKey();
            Console.ReadKey();
            Console.Clear();
            SmileEmoji.Emoji();
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Thanks for playing the Number Game, give it another try!");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine();
            Console.BackgroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("Press any key to exit...");
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ReadKey();

            Environment.Exit(0);
        }
예제 #3
0
        public static string UserName()
        {
            //Use validation proof to make sure you get something for a name or nickname

            while (true)
            {
                Console.Clear();
                SmileEmoji.Emoji();
                Console.WriteLine();
                Console.WriteLine("Lets play The Number Game!");
                //Ask the user for thier name and catch it in a string

                Console.WriteLine("\nWhat is your name?");
                Console.WriteLine();
                Console.BackgroundColor = ConsoleColor.DarkBlue;
                Console.WriteLine("When done Typing your Name press Enter");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.BackgroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("If you wish to exit the Number Game simply type the word \"exit\"");
                Console.BackgroundColor = ConsoleColor.Black;
                string aname = Console.ReadLine();
                aname = aname.ToUpper();
                Console.Clear();

                if (aname == "EXIT")
                {
                    Console.Clear();
                    ExitOption.Exit();
                }
                else if (aname.Length < 1)
                {
                    SmileEmoji.Emoji();
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("Hmm..no name received..?");
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.WriteLine();
                    Console.WriteLine("Press any key to continue.");
                    Console.ReadKey();
                    continue;
                }
                else if (aname == " " || aname == "  " || aname == "   " || aname == "    " || aname == "     " || aname == "      " || aname == "       " || aname == "        " || aname == "         " || aname == "          ")
                {
                    SmileEmoji.Emoji();
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("Hmm..no name received..?");
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.WriteLine();
                    Console.WriteLine("Press any key to continue.");
                    Console.ReadKey();
                    continue;
                }
                else if (aname.Length > int.MaxValue)
                {
                    SmileEmoji.Emoji();
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("Hmm..could not register name..?");
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.WriteLine();
                    Console.WriteLine("Press any key to continue.");
                    Console.ReadKey();
                    continue;
                }
                else if (aname.Length > 0)
                {
                    //Welcome the user by the name they had input

                    Console.WriteLine("\nHello " + aname + "! \n" + "\nWelcome to The Number Game!");
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                    Console.WriteLine("Press any key to continue...");
                    Console.BackgroundColor = ConsoleColor.Black;
                    Console.ReadKey();
                    Console.Clear();
                    return(aname);
                }
            }
        }