Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. using System;
  2.  
  3. namespace homework_03_2
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Console.CursorVisible = false;
  10.  
  11. Random random = new Random();
  12.  
  13. int countKey = 0;
  14. int live = 2;
  15. bool isWin = false;
  16.  
  17. char[,] map =
  18. {
  19. {'#','#','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#','#','#','#','#','#','#','#' },
  20. {'#',' ',' ',' ',' ',' ','X','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#' },
  21. {'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#' },
  22. {'#',' ',' ',' ',' ',' ',' ','#','#','#','#','#','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ','#' },
  23. {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','<','<','<',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  24. {'#',' ',' ',' ',' ',' ',' ','#','#','#','#','#','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ','#' },
  25. {'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#' },
  26. {'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#' },
  27. {'#','X',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ','X',' ',' ',' ',' ','#' },
  28. {'#','#','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#','#','#','#','#','#','#','#' },
  29. };
  30.  
  31. int userX = 2, userY = 3;
  32. // char[] bag = new char[0];
  33.  
  34. while (live != 0)
  35. {
  36. Console.SetCursorPosition(0, 0);
  37.  
  38. for (int i = 0; i < map.GetLength(0); i++)
  39. {
  40. for (int j = 0; j < map.GetLength(1); j++)
  41. {
  42. Console.Write(map[i, j]);
  43. }
  44.  
  45. Console.WriteLine();
  46. }
  47.  
  48. if (countKey != 3)
  49. {
  50. Console.BackgroundColor = ConsoleColor.Red;
  51. Console.SetCursorPosition(0, 1);
  52. Console.Write('#');
  53. Console.BackgroundColor = ConsoleColor.Black;
  54. }
  55. else
  56. {
  57. Console.BackgroundColor = ConsoleColor.Yellow;
  58. Console.SetCursorPosition(1, 1);
  59. map[1, 0] = '-';
  60. Console.BackgroundColor = ConsoleColor.Black;
  61. }
  62.  
  63. Console.SetCursorPosition(30, 0);
  64. Console.BackgroundColor = ConsoleColor.Red;
  65. Console.WriteLine("Задание: ");
  66. Console.BackgroundColor = ConsoleColor.Black;
  67.  
  68. Console.SetCursorPosition(30, 1);
  69. Console.WriteLine("Найдите все ключи и выйдите из лабиринта.");
  70. Console.SetCursorPosition(30, 3);
  71. Console.Write("Жизни L : ");
  72. for (int i = 0; i < live; i++)
  73. {
  74. Console.Write("O");
  75. }
  76. Console.SetCursorPosition(30, 4);
  77. Console.WriteLine("Ключи Х : " + countKey);
  78.  
  79. Console.SetCursorPosition(userY, userX);
  80. Console.Write('@');
  81. ConsoleKeyInfo charKey = Console.ReadKey();
  82.  
  83. switch (charKey.Key)
  84. {
  85. case ConsoleKey.UpArrow:
  86. if (map[userX - 1, userY] != '#')
  87. userX--;
  88. break;
  89. case ConsoleKey.DownArrow:
  90. if (map[userX + 1, userY] != '#')
  91. userX++;
  92. break;
  93. case ConsoleKey.LeftArrow:
  94. if (map[userX, userY - 1] != '#')
  95. userY--;
  96. break;
  97. case ConsoleKey.RightArrow:
  98. if (map[userX, userY + 1] != '#')
  99. userY++;
  100. break;
  101. }
  102.  
  103. if (map[userX, userY + 1] == '<')
  104. {
  105. live--;
  106. map[userX, userY + 1] = ' ';
  107. }
  108. else if (map[userX, userY] == 'X')
  109. {
  110. countKey++;
  111. map[userX, userY] = ' ';
  112.  
  113. if (map[4, 11] == '<')
  114. {
  115. map[4, 11] = ' ';
  116. }
  117. else if (map[4, 12] == '<')
  118. {
  119. map[4, 12] = ' ';
  120. }
  121. else if (map[4, 13] == '<')
  122. {
  123. map[4, 13] = ' ';
  124. }
  125. }
  126. else if (map[userX, userY] == '-')
  127. {
  128. isWin = true;
  129. break;
  130. }
  131. Console.Clear();
  132. }
  133.  
  134. Console.Clear();
  135. Console.SetCursorPosition(0, 0);
  136.  
  137. Console.BackgroundColor = ConsoleColor.Red;
  138. if (isWin)
  139. Console.WriteLine("Вы выйграли!!!");
  140. else
  141. Console.WriteLine("Вы проиграли");
  142. Console.BackgroundColor = ConsoleColor.Black;
  143. }
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement