Advertisement
Guest User

Mastermind

a guest
Apr 21st, 2017
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MasterMind
  4. {
  5. class Game
  6. {
  7. public void DrawStart()
  8. {
  9. Console.Clear();
  10. Random rnd = new Random();
  11. int numberOne = rnd.Next(1, 7); //This is generating a random number and is saving it within the variable numberOne
  12. int numberTwo = rnd.Next(1, 7); //This is generating a random number and is saving it within the variable numberTwo
  13. int numberThree = rnd.Next(1, 7); //This is generating a random number and is saving it within the variable numberThree
  14. int numberFour = rnd.Next(1, 7); //This is generating a random number and is saving it within the variable numberFour
  15. Console.WriteLine("This is your first guess.");
  16. Console.WriteLine("Good luck");
  17. string gnumberOne = Console.ReadKey().KeyChar.ToString();
  18. string gnumberTwo = Console.ReadKey().KeyChar.ToString();
  19. string gnumberThree = Console.ReadKey().KeyChar.ToString();
  20. string gnumberFour = Console.ReadKey().KeyChar.ToString();
  21. Console.WriteLine("These are the random numbers");
  22. Console.WriteLine(numberOne);
  23. Console.WriteLine(numberTwo);
  24. Console.WriteLine(numberThree);
  25. Console.WriteLine(numberFour);
  26. Console.ReadKey();
  27. }
  28. }
  29. class Menu
  30. {
  31. public void DrawMainMenu() // This can be used publically to draw the main menu.
  32. {
  33. Console.ForegroundColor = ConsoleColor.Green;
  34. Console.Clear();
  35. var game = new Game(); // Loading in from another class so it can be used. Used for DrawStart
  36. Console.WriteLine("MasterMind's Main Menu");
  37. Console.WriteLine("1: Play");
  38. Console.WriteLine("2: Help");
  39. Console.WriteLine("0: Exit");
  40. string userInput = Console.ReadKey().KeyChar.ToString(); //Captures the users input.
  41. if (userInput == "1")
  42. {
  43. Console.Clear();
  44. game.DrawStart();
  45. }
  46. if (userInput == "2")
  47. {
  48. Console.Clear();
  49. DrawHelp();
  50. }
  51. if (userInput == "0")
  52. {
  53. DrawExit();
  54. Console.ReadLine();
  55. }
  56. else // This repeats the menu for if a value which isnt 1, 2 or 0 is entered.
  57. {
  58. Console.Clear();
  59. DrawMainMenu();
  60. }
  61. }
  62. public void DrawHelp() // This is used to print out the help menu.
  63. {
  64. Console.Clear();
  65. Console.WriteLine("Rules Of MasterMind!");
  66. Console.WriteLine("Mastermind is a game about guessing a 4 digit code. The numbers can range from");
  67. Console.WriteLine("1-4 and any other numbers will be rejected. It will say in the CMD");
  68. Console.WriteLine("prompt whether or not you had any of the number correct or false.");
  69. Console.WriteLine("Press any key to go back to the main menu.");
  70. Console.ReadKey();
  71. Console.Clear();
  72. DrawMainMenu();
  73. Console.ReadLine();
  74. }
  75. public void DrawExit() // This is used to check whether or not the user wants to quit the game.
  76. {
  77. Console.Clear();
  78. Console.WriteLine("You are about to exit the game");
  79. Console.WriteLine("Are you sure: Y/N");
  80. string userExit = Console.ReadKey().KeyChar.ToString();
  81. if (userExit == "Y")
  82. {
  83. Environment.Exit(0);
  84. }
  85. if (userExit == "y")
  86. {
  87. Environment.Exit(0);
  88. }
  89. if (userExit == "N")
  90. {
  91. Console.Clear();
  92. DrawMainMenu();
  93. Console.ReadLine();
  94. }
  95. if (userExit == "n")
  96. {
  97. Console.Clear();
  98. DrawMainMenu();
  99. Console.ReadLine();
  100. }
  101. else
  102. {
  103. Console.Clear();
  104. DrawExit();
  105. }
  106. }
  107. }
  108. class Program
  109. {
  110. static void Main(string[] args)
  111. {
  112. var menu = new Menu();
  113. var game = new Game();
  114. menu.DrawMainMenu();
  115. string userInput = Console.ReadKey().KeyChar.ToString();
  116. if (userInput == "1")
  117. {
  118. Console.Clear();
  119. game.DrawStart();
  120. }
  121. if (userInput == "2") //This draws the rules and help menu.
  122. {
  123. menu.DrawHelp();
  124. }
  125. if (userInput == "0") //This draws the exit.
  126. {
  127. menu.DrawExit();
  128. Console.ReadLine();
  129. }
  130. }
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement