Advertisement
o91leg

Untitled

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