Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace GuessTheNumber
- {
- class Program
- {
- static void Main(string[] args)
- {
- Welcome();
- }
- public static void Welcome()
- {
- Console.WriteLine("Welcome to the Guess the Number Game");
- Console.ReadKey();
- Console.Clear();
- int number = ChooseDifficulty();
- //Console.WriteLine($"I'm thinking of a number between {num1} and {num2}, you have 5 guesses");
- bool won = false;
- int tries = 0;
- while ((won != true) || (tries < 5)) //keep looping while player hasnt won.
- {
- Console.Write($"Guess number {tries + 1}: Guess a Number..");
- System.Diagnostics.Debug.WriteLine($"tries = {tries}");
- int guess = Convert.ToInt32(Console.ReadLine());
- if (guess < number)
- {
- Console.WriteLine("You guessed too low");
- }
- else if (guess > number)
- {
- Console.WriteLine("You guessed too high");
- }
- else if (guess == number)
- {
- Console.WriteLine($"Congratulations, You guessed correctly, I was indeed thinking of {number}");
- won = true;
- }
- tries++;
- }
- }
- public int ChooseDifficulty()
- {
- Console.WriteLine("Choose a Difficulty:\n");
- Console.WriteLine("1 - Easy");
- Console.WriteLine("2 - Medium");
- Console.WriteLine("3 - Hard");
- Console.WriteLine("4 - Insane");
- int difficulty = Convert.ToInt32(Console.ReadLine());
- int num;
- switch (difficulty)
- {
- case 1:
- num = RandNumber(0, 10);
- return num; //return random number
- case 2:
- num = RandNumber(0, 100);
- return num;
- case 3:
- num = RandNumber(0, 500);
- return num;
- case 4:
- num = RandNumber(0, 1000);
- return num;
- default:
- Console.WriteLine("Invalid Choice");
- ChooseDifficulty();
- break;
- }
- }
- public int RandNumber(int num1, int num2)
- {
- Random RandomNumber = new System.Random();
- return RandomNumber.Next(num1, num2); //random num between 1 and whatever. TODO return num1 and num2 to programmatically write limits of guess
- }
- static void GameOver()
- {
- Console.WriteLine("Game Over!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement