Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace MasterMind
- {
- class Game
- {
- public void DrawStart()
- {
- Console.Clear();
- Random rnd = new Random();
- int numberOne = rnd.Next(1, 7); //This is generating a random number and is saving it within the variable numberOne
- int numberTwo = rnd.Next(1, 7); //This is generating a random number and is saving it within the variable numberTwo
- int numberThree = rnd.Next(1, 7); //This is generating a random number and is saving it within the variable numberThree
- int numberFour = rnd.Next(1, 7); //This is generating a random number and is saving it within the variable numberFour
- Console.WriteLine("This is your first guess.");
- Console.WriteLine("Good luck");
- string gnumberOne = Console.ReadKey().KeyChar.ToString();
- string gnumberTwo = Console.ReadKey().KeyChar.ToString();
- string gnumberThree = Console.ReadKey().KeyChar.ToString();
- string gnumberFour = Console.ReadKey().KeyChar.ToString();
- Console.WriteLine("These are the random numbers");
- Console.WriteLine(numberOne);
- Console.WriteLine(numberTwo);
- Console.WriteLine(numberThree);
- Console.WriteLine(numberFour);
- Console.ReadKey();
- }
- }
- class Menu
- {
- public void DrawMainMenu() // This can be used publically to draw the main menu.
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Clear();
- var game = new Game(); // Loading in from another class so it can be used. Used for DrawStart
- Console.WriteLine("MasterMind's Main Menu");
- Console.WriteLine("1: Play");
- Console.WriteLine("2: Help");
- Console.WriteLine("0: Exit");
- string userInput = Console.ReadKey().KeyChar.ToString(); //Captures the users input.
- if (userInput == "1")
- {
- Console.Clear();
- game.DrawStart();
- }
- if (userInput == "2")
- {
- Console.Clear();
- DrawHelp();
- }
- if (userInput == "0")
- {
- DrawExit();
- Console.ReadLine();
- }
- else // This repeats the menu for if a value which isnt 1, 2 or 0 is entered.
- {
- Console.Clear();
- DrawMainMenu();
- }
- }
- public void DrawHelp() // This is used to print out the help menu.
- {
- Console.Clear();
- Console.WriteLine("Rules Of MasterMind!");
- Console.WriteLine("Mastermind is a game about guessing a 4 digit code. The numbers can range from");
- Console.WriteLine("1-4 and any other numbers will be rejected. It will say in the CMD");
- Console.WriteLine("prompt whether or not you had any of the number correct or false.");
- Console.WriteLine("Press any key to go back to the main menu.");
- Console.ReadKey();
- Console.Clear();
- DrawMainMenu();
- Console.ReadLine();
- }
- public void DrawExit() // This is used to check whether or not the user wants to quit the game.
- {
- Console.Clear();
- Console.WriteLine("You are about to exit the game");
- Console.WriteLine("Are you sure: Y/N");
- string userExit = Console.ReadKey().KeyChar.ToString();
- if (userExit == "Y")
- {
- Environment.Exit(0);
- }
- if (userExit == "y")
- {
- Environment.Exit(0);
- }
- if (userExit == "N")
- {
- Console.Clear();
- DrawMainMenu();
- Console.ReadLine();
- }
- if (userExit == "n")
- {
- Console.Clear();
- DrawMainMenu();
- Console.ReadLine();
- }
- else
- {
- Console.Clear();
- DrawExit();
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- var menu = new Menu();
- var game = new Game();
- menu.DrawMainMenu();
- string userInput = Console.ReadKey().KeyChar.ToString();
- if (userInput == "1")
- {
- Console.Clear();
- game.DrawStart();
- }
- if (userInput == "2") //This draws the rules and help menu.
- {
- menu.DrawHelp();
- }
- if (userInput == "0") //This draws the exit.
- {
- menu.DrawExit();
- Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement