Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 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. using System.IO;
  7.  
  8. namespace Lesson2
  9. {
  10. class Program
  11. {
  12.  
  13. static void Main(string[] args)
  14. {
  15.  
  16. Console.CursorVisible = false;
  17. char[,] map =
  18. {
  19. { '█','█','█','█','█','█','█','█','█','█','█'},
  20. { '█',' ',' ',' ',' ',' ',' ',' ',' ',' ','█'},
  21. { '█',' ',' ','╬',' ','█',' ','█',' ',' ','█'},
  22. { '█',' ','█',' ',' ',' ','╬',' ',' ',' ','█'},
  23. { '█',' ',' ','█',' ',' ',' ',' ',' ',' ','█'},
  24. { '█',' ',' ','╬',' ',' ',' ','╬','█',' ','█'},
  25. { '█',' ',' ',' ',' ',' ',' ',' ',' ',' ','█'},
  26. { '█',' ','█',' ',' ',' ','╬','█',' ',' ','█'},
  27. { '█',' ',' ',' ',' ','█',' ',' ',' ',' ','█'},
  28. { '█',' ',' ',' ',' ',' ',' ',' ',' ',' ','█'},
  29. { '█','█','█','█','█','█','█','█','█','█','█'}
  30. };
  31. Console.Write("\n Вам всего-то нужно собрать все 5 крестов.");
  32. Console.Write("\n Если застряли, попробуйте заново.");
  33.  
  34.  
  35. char[] bag = new char[0];
  36. int userX = 5, userY = 5;
  37.  
  38. while (true)
  39. {
  40. MapDraw(map);
  41. Console.SetCursorPosition(11, 0);
  42. Console.Write("Сумка: ");
  43. for (int i = 0; i < bag.Length; i++)
  44. Console.Write(bag[i] + " | ");
  45.  
  46. Console.BackgroundColor = ConsoleColor.Blue;
  47. Console.SetCursorPosition(userY, userX);
  48. Console.Write('@');
  49. ConsoleKeyInfo charKey = Console.ReadKey();
  50. switch (charKey.Key)
  51. {
  52. case ConsoleKey.UpArrow:
  53. while (map[userX - 1, userY] != '█')
  54. {
  55. userX--;
  56. if (map[userX, userY] == '╬')
  57. {
  58. map[userX, userY] = ' ';
  59. char[] tempBag = new char[bag.Length + 1];
  60. for (int i = 0; i < bag.Length; i++)
  61. {
  62. tempBag[i] = bag[i];
  63. }
  64. tempBag[tempBag.Length - 1] = '╬';
  65. bag = tempBag;
  66.  
  67. }
  68. }
  69.  
  70. break;
  71. case ConsoleKey.DownArrow:
  72. while (map[userX + 1, userY] != '█')
  73. {
  74. userX++;
  75. if (map[userX, userY] == '╬')
  76. {
  77. map[userX, userY] = ' ';
  78. char[] tempBag = new char[bag.Length + 1];
  79. for (int i = 0; i < bag.Length; i++)
  80. {
  81. tempBag[i] = bag[i];
  82. }
  83. tempBag[tempBag.Length - 1] = '╬';
  84. bag = tempBag;
  85.  
  86. }
  87. }
  88.  
  89. break;
  90. case ConsoleKey.LeftArrow:
  91. while (map[userX, userY - 1] != '█')
  92. {
  93. userY--;
  94. if (map[userX, userY] == '╬')
  95. {
  96. map[userX, userY] = ' ';
  97. char[] tempBag = new char[bag.Length + 1];
  98. for (int i = 0; i < bag.Length; i++)
  99. {
  100. tempBag[i] = bag[i];
  101. }
  102. tempBag[tempBag.Length - 1] = '╬';
  103. bag = tempBag;
  104.  
  105. }
  106. }
  107.  
  108. break;
  109. case ConsoleKey.RightArrow:
  110. while (map[userX, userY + 1] != '█')
  111. {
  112. userY++;
  113. if (map[userX, userY] == '╬')
  114. {
  115. map[userX, userY] = ' ';
  116. char[] tempBag = new char[bag.Length + 1];
  117. for (int i = 0; i < bag.Length; i++)
  118. {
  119. tempBag[i] = bag[i];
  120. }
  121. tempBag[tempBag.Length - 1] = '╬';
  122. bag = tempBag;
  123.  
  124. }
  125. }
  126.  
  127. break;
  128. }
  129. Console.BackgroundColor = ConsoleColor.Black;
  130. if (bag.Length == 5)
  131. {
  132. Console.Clear();
  133. Console.WriteLine("Вам удалось собрать все кресты, поздравляю!!!\nПопробуйте еще раз)");
  134. break;
  135. }
  136. }
  137. }
  138.  
  139.  
  140. static void MapDraw(char[,] arr)
  141. {
  142. Console.BackgroundColor = ConsoleColor.Blue;
  143. Console.SetCursorPosition(0, 0);
  144. for (int i = 0; i < arr.GetLength(0); i++)
  145. {
  146. for (int j = 0; j < arr.GetLength(1); j++)
  147. {
  148. Console.Write(arr[i, j]);
  149. }
  150. Console.WriteLine();
  151. }
  152. Console.BackgroundColor = ConsoleColor.Black;
  153. }
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement