Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1.  
  2. using System;
  3.  
  4. namespace CsLight
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. Console.CursorVisible = false;
  11.  
  12. char[,] map =
  13. {
  14. {'#','#','#','#','#','#','#','#','#','#','#','#' },
  15. {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  16. {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  17. {'#',' ',' ',' ',' ',' ',' ','*',' ',' ','X','#' },
  18. {'#',' ',' ','X',' ',' ',' ',' ',' ',' ',' ','#' },
  19. {'#',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  20. {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  21. {'#',' ',' ',' ',' ',' ',' ',' ','X',' ',' ','#' },
  22. {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  23. {'#','#','#','#','#','#','#','#','#','#','#','#' }
  24. };
  25.  
  26. int userY = 1, userX = 1;
  27. char[] bag = new char[0];
  28. int win = 0;
  29.  
  30. while (true)
  31. {
  32. Console.SetCursorPosition(20, 0);
  33. Console.Write("Сумка: ");
  34. for (int i = 0; i < bag.Length; i++)
  35. Console.Write(bag[i] + " | ");
  36. Console.SetCursorPosition(0, 0);
  37. for (int i = 0; i < map.GetLength(0); i++)
  38. {
  39. for (int j = 0; j < map.GetLength(1); j++)
  40. {
  41. Console.Write(map[i, j]);
  42. }
  43. Console.WriteLine();
  44. }
  45.  
  46. Console.SetCursorPosition(userY, userX);
  47. Console.Write('@');
  48. ConsoleKeyInfo charKey = Console.ReadKey();
  49.  
  50. switch (charKey.Key)
  51. {
  52. case ConsoleKey.UpArrow:
  53. if (map[userX - 1, userY] != '#')
  54. userX--;
  55. break;
  56. case ConsoleKey.DownArrow:
  57. if (map[userX + 1, userY] != '#')
  58. userX++;
  59. break;
  60. case ConsoleKey.LeftArrow:
  61. if (map[userX, userY - 1] != '#')
  62. userY--;
  63. break;
  64. case ConsoleKey.RightArrow:
  65. if (map[userX, userY + 1] != '#')
  66. userY++;
  67. break;
  68. }
  69.  
  70. if (map[userX, userY] == 'X')
  71. {
  72. map[userX, userY] = 'O';
  73.  
  74. char[] tempBag = new char[bag.Length + 1];
  75.  
  76. for (int i = 0; i < bag.Length; i++)
  77. {
  78. tempBag[i] = bag[i];
  79. }
  80. tempBag[tempBag.Length - 1] = 'X';
  81. bag = tempBag;
  82. win++;
  83. }
  84. if (map[userX, userY] == '*')
  85. {
  86. Console.WriteLine("...You died...");
  87. break;
  88. }
  89. if(win == 3)
  90. {
  91. Console.WriteLine("...You win...");
  92. break;
  93. }
  94. }
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement