Advertisement
Guest User

Untitled

a guest
Jun 1st, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace ConsoleApp20
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14.  
  15. char[,] matrix = new char[n,n];
  16.  
  17.  
  18. int minerRow = -1;
  19. int minerCol = -1;
  20.  
  21. int coalCount = 0;
  22. int collectedCoal = 0;
  23.  
  24. int endRow = -1;
  25. int endCol = -1;
  26.  
  27. bool progHasEnded = false;
  28.  
  29. string[] directions = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
  30.  
  31. //ПРОБЛЕМ!
  32. //colVals ReadLine-a чете и празните места и не взима цялата матрица
  33. //////////////////////////////////////////////////////
  34. for (int row = 0; row < n; row++)
  35. {
  36. char[] colVals = Console.ReadLine().ToCharArray();
  37.  
  38. for (int col = 0; col < n; col++)
  39. {
  40. matrix[row, col] = colVals[col];
  41. ///////////////////////////////////////////////////////
  42.  
  43. if (colVals[col] == 's')
  44. {
  45. minerRow = row;
  46. minerCol = col;
  47. }
  48.  
  49. if (colVals[col] == 'c')
  50. {
  51. coalCount++;
  52. }
  53.  
  54. if (colVals[col] == 'e')
  55. {
  56. endRow = row;
  57. endCol = col;
  58.  
  59. }
  60. }
  61. }
  62.  
  63. //Цикъл за изписване на матрицата при проверки
  64. //for (int row = 0; row < n; row++)
  65. //{
  66. // for (int col = 0; col < n; col++)
  67. // {
  68. // Console.Write(matrix[row, col]);
  69. // }
  70.  
  71. // Console.WriteLine();
  72. //}
  73.  
  74. foreach (string direction in directions)
  75. {
  76. int currMnRow = minerRow;
  77. int currMnCol = minerCol;
  78.  
  79. switch (direction)
  80. {
  81. case "up":
  82.  
  83. if (!(currMnRow - 1 < 0))
  84. {
  85. currMnRow--;
  86. }
  87.  
  88. break;
  89.  
  90. case "down":
  91.  
  92. if (!(currMnRow + 1 >= n))
  93. {
  94. currMnRow++;
  95. }
  96.  
  97. break;
  98.  
  99. case "left":
  100.  
  101. if (!(currMnCol - 1 < 0))
  102. {
  103. currMnCol--;
  104. }
  105.  
  106. break;
  107.  
  108. case "right":
  109.  
  110. if (!(currMnCol + 1 >= n))
  111. {
  112. currMnCol++;
  113. }
  114.  
  115. break;
  116. }
  117.  
  118.  
  119. if (matrix[currMnRow, currMnCol] == 'c')
  120. {
  121. matrix[minerRow, minerCol] = '*';
  122. matrix[currMnRow, currMnCol] = 's';
  123.  
  124. coalCount--;
  125. collectedCoal++;
  126.  
  127. minerRow = currMnRow;
  128. minerCol = currMnCol;
  129.  
  130. if (coalCount == 0)
  131. {
  132. Console.WriteLine($"You collected all coals! ({minerRow}, {minerCol})");
  133. progHasEnded = true;
  134. break;
  135. }
  136. }
  137. else if (matrix[currMnRow, currMnCol] == 'e')
  138. {
  139. matrix[minerRow, minerCol] = '*';
  140.  
  141. minerRow = currMnRow;
  142. minerCol = currMnCol;
  143.  
  144. Console.WriteLine($"Game over! ({endRow}, {endCol})");
  145. progHasEnded = true;
  146. break;
  147. }
  148.  
  149. }
  150.  
  151.  
  152.  
  153. if (!progHasEnded)
  154. {
  155. Console.WriteLine($"{coalCount - collectedCoal} coals left. ({minerRow}, {minerCol})");
  156. }
  157.  
  158. }
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement