Advertisement
lolblach333

Untitled

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