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(ref char[,] map)
  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(char[,] map)
  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.  
  175.  
  176.  
  177.  
  178. static void Main(string[] args)
  179. {
  180. Program program = new Program();
  181.  
  182. Point player;
  183.  
  184. showStartText();
  185.  
  186. Console.Write("Press enter to continue.");
  187.  
  188. Console.ReadLine();
  189.  
  190. Console.Clear();
  191.  
  192.  
  193. while (true)
  194. {
  195. generateMap(ref map);
  196.  
  197. player.x = 1;
  198. player.y = 1;
  199.  
  200. for (int i = 6; i >= 0; --i)
  201. {
  202. Console.Clear();
  203.  
  204. drawMap(map);
  205.  
  206. Console.ForegroundColor = ConsoleColor.Gray;
  207.  
  208. Console.Write("\n\nYou have ");
  209. Console.Write(i);
  210. Console.Write(" seconds left.");
  211.  
  212. System.Threading.Thread.Sleep(1000);
  213. }
  214.  
  215. Console.Clear();
  216.  
  217. while (true)
  218. {
  219. Console.Clear();
  220.  
  221. Console.Write("Press an arrow key to go that direction");
  222. }
  223.  
  224.  
  225. }
  226.  
  227. }
  228. }
  229. }
  230.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty