fork download
  1. using System;
  2. using System.Text;
  3.  
  4.  
  5. namespace Memory_Maze
  6. {
  7. class Program
  8. {
  9. static char[,] map = new char[20, 20];
  10.  
  11. static Random random = new Random();
  12.  
  13. struct Point
  14. {
  15. public int x;
  16. public int y;
  17.  
  18. /*void move(ref char[,] map, Console.)
  19.   {
  20.  
  21.   }*/
  22. }
  23.  
  24.  
  25. static Point player;
  26.  
  27.  
  28.  
  29.  
  30.  
  31. static void showStartText()
  32. {
  33. Console.Write("~~~Memory Maze~~~\n\n");
  34.  
  35. Console.Write("How good is your short term memory? Time to put it to the test!\n\n");
  36.  
  37. Console.Write("Instructions: You will be shown a map. The 'S' is the start, and the 'F' is the end.\n\n");
  38.  
  39. Console.Write("You will be shown the maze for a few seconds, and then you must try to navigate from start to finish.\n\n");
  40.  
  41. Console.Write("To move in a direction, hit that arrow key. If you run into a wall, you lose.\n\n");
  42. }
  43.  
  44. static void generateMap()
  45. {
  46. for (int x = 0; x < map.GetLength(0); ++x)
  47. for (int y = 0; y < map.GetLength(1); ++y)
  48. {
  49. map[x, y] = 'W';
  50. }
  51.  
  52. int tunnelX = 1;
  53. int tunnelY = 1;
  54.  
  55. map[tunnelX, tunnelY] = 'S';
  56.  
  57. while (true)
  58. {
  59. if (random.Next(0, 2) == 1)
  60. {
  61. if (tunnelX + 1 < map.GetLength(0) - 1)
  62. {
  63. ++tunnelX;
  64.  
  65. map[tunnelX, tunnelY] = ' ';
  66.  
  67. continue;
  68. }
  69. else
  70. {
  71. if (tunnelY + 1 < map.GetLength(1) - 1)
  72. {
  73. ++tunnelY;
  74.  
  75. map[tunnelX, tunnelY] = ' ';
  76. }
  77. else
  78. {
  79. map[tunnelX, tunnelY] = 'F';
  80.  
  81. break;
  82. }
  83. }
  84. }
  85. else
  86. {
  87. if (tunnelY + 1 < map.GetLength(1) - 1)
  88. {
  89. ++tunnelY;
  90.  
  91. map[tunnelX, tunnelY] = ' ';
  92.  
  93. continue;
  94. }
  95. else
  96. {
  97. if (tunnelX + 1 < map.GetLength(0) - 1)
  98. {
  99. ++tunnelX;
  100.  
  101. map[tunnelX, tunnelY] = ' ';
  102. }
  103. else
  104. {
  105. map[tunnelX, tunnelY] = 'F';
  106.  
  107. break;
  108. }
  109. }
  110. }
  111. }
  112. }
  113.  
  114. static void drawMap()
  115. {
  116. for (int x = 0; x < map.GetLength(0); ++x)
  117. {
  118. for (int y = 0; y < map.GetLength(1); ++y)
  119. {
  120. switch (map[x, y])
  121. {
  122. case 'W':
  123. Console.ForegroundColor = ConsoleColor.Red;
  124. break;
  125.  
  126. case 'P':
  127. Console.ForegroundColor = ConsoleColor.Green;
  128. break;
  129.  
  130. case 'S':
  131. Console.ForegroundColor = ConsoleColor.Cyan;
  132. break;
  133.  
  134. case 'F':
  135. Console.ForegroundColor = ConsoleColor.Magenta;
  136. break;
  137.  
  138. }
  139.  
  140. Console.Write(map[x, y]);
  141. }
  142.  
  143. Console.Write("\n");
  144. }
  145. }
  146.  
  147. static bool quit()
  148. {
  149. while (true)
  150. {
  151. Console.ForegroundColor = ConsoleColor.Red;
  152.  
  153. Console.Write("Would you like to play again? y/n\n");
  154.  
  155. Console.ForegroundColor = ConsoleColor.Green;
  156.  
  157. string input = Console.ReadLine();
  158.  
  159. Console.ForegroundColor = ConsoleColor.Gray;
  160.  
  161. if (input.ToLowerInvariant() == "y")
  162. return false;
  163. else if (input.ToLowerInvariant() == "n")
  164. return true;
  165. else
  166. {
  167. Console.Write("\n\nInvalid input\n\n");
  168.  
  169. continue;
  170. }
  171. }
  172. }
  173.  
  174. static bool movePlayer()
  175. {
  176. var key = Console.ReadKey();
  177.  
  178. if (key.Key == ConsoleKey.RightArrow)
  179. {
  180. ++player.x;
  181.  
  182. if (map[player.x, player.y] == 'W')
  183. return false;
  184. else
  185. return true;
  186. }
  187. else if (key.Key == ConsoleKey.DownArrow)
  188. {
  189. ++player.y;
  190.  
  191. if (map[player.x, player.y] == 'W')
  192. return false;
  193. else
  194. return true;
  195. }
  196.  
  197. return true;
  198. }
  199.  
  200. static bool won()
  201. {
  202. if (map[player.x, player.y] == 'F')
  203. return true;
  204. else
  205. Console.Write("False\n");
  206.  
  207. return false;
  208. }
  209.  
  210.  
  211.  
  212.  
  213.  
  214. static void Main(string[] args)
  215. {
  216. Program program = new Program();
  217.  
  218. Point player;
  219.  
  220. showStartText();
  221.  
  222. Console.Write("Press enter to continue.");
  223.  
  224. Console.ReadLine();
  225.  
  226. Console.Clear();
  227.  
  228.  
  229. while (true)
  230. {
  231. Console.Clear();
  232.  
  233. generateMap();
  234.  
  235. player.x = map.GetLength(0) - 2;
  236. player.y = map.GetLength(1) - 2;
  237.  
  238. drawMap();
  239.  
  240. Console.ForegroundColor = ConsoleColor.Gray;
  241.  
  242. Console.Write("\n\nSeconds left: 6");
  243.  
  244. Console.ForegroundColor = ConsoleColor.Green;
  245.  
  246. for (int i = 6; i >= 0; --i)
  247. {
  248. Console.Write("\b");
  249.  
  250. Console.Write(i);
  251.  
  252. System.Threading.Thread.Sleep(1000);
  253. }
  254.  
  255. Console.ForegroundColor = ConsoleColor.Gray;
  256.  
  257. Console.Clear();
  258.  
  259. while (true)
  260. {
  261. Console.Clear();
  262.  
  263. Console.Write("Press an arrow key to go that direction\n");
  264.  
  265. if (true)
  266. {
  267. if (won())
  268. {
  269. Console.Write("Congratulations, you won!\n\n");
  270.  
  271. if (quit())
  272. return;
  273. else
  274. break;
  275. }
  276.  
  277. continue;
  278. }
  279. else
  280. {
  281. Console.Write("You ran into a wall.\n\n");
  282.  
  283. if (quit())
  284. return;
  285. else
  286. break;
  287. }
  288. }
  289.  
  290.  
  291. }
  292.  
  293. }
  294. }
  295. }
  296.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty