Advertisement
softy_02

Re-Volt

Jun 20th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.59 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Re_Volt_Again
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. var side = int.Parse(Console.ReadLine());
  10. var count = int.Parse(Console.ReadLine());
  11. var matrix = new char[side, side];
  12. var playerRow = 0;
  13. var playerCol = 0;
  14.  
  15. for (int row = 0; row < side; row++)
  16. {
  17. var input = Console.ReadLine().ToCharArray();
  18.  
  19. for (int col = 0; col < side; col++)
  20. {
  21. matrix[row, col] = input[col];
  22. if (matrix[row, col] == 'f')
  23. {
  24. playerRow = row;
  25. playerCol = col;
  26. }
  27. }
  28. }
  29.  
  30. var startRow = playerRow;
  31. var startCol = playerCol;
  32.  
  33. for (int i = 0; i < count; i++)
  34. {
  35. var command = Console.ReadLine();
  36.  
  37.  
  38. if (command == "up")
  39. {
  40. if (playerRow - 1 < 0)
  41. {
  42. playerRow = matrix.GetLength(0) - 1;
  43. }
  44. else
  45. {
  46. playerRow--;
  47. }
  48. if (matrix[playerRow, playerCol] == 'B')
  49. {
  50. if (playerRow - 1 < 0)
  51. {
  52. playerRow = matrix.GetLength(0) - 1;
  53. }
  54. else
  55. {
  56. playerRow--;
  57. }
  58. }
  59. if (matrix[playerRow, playerCol] == 'T')
  60. {
  61. if (playerRow + 1 >= matrix.GetLength(0))
  62. {
  63. playerRow = 0;
  64. }
  65. else
  66. {
  67. playerRow++;
  68. }
  69. }
  70. if (matrix[playerRow, playerCol] == 'F')
  71. {
  72. matrix[startRow, startCol] = '-';
  73. matrix[playerRow, playerCol] = 'f';
  74. Console.WriteLine("Player won!");
  75. PrintMatrix(matrix);
  76. return;
  77. }
  78.  
  79.  
  80. }
  81. else if (command == "down")
  82. {
  83. if (playerRow + 1 >= matrix.GetLength(0))
  84. {
  85. playerRow = 0;
  86. }
  87. else
  88. {
  89. playerRow++;
  90. }
  91. if (matrix[playerRow, playerCol] == 'B')
  92. {
  93. if (playerRow + 1 >= matrix.GetLength(0))
  94. {
  95. playerRow = 0;
  96. }
  97. else
  98. {
  99. playerRow++;
  100. }
  101.  
  102. }
  103. if (matrix[playerRow, playerCol] == 'T')
  104. {
  105. if (playerRow - 1 < 0)
  106. {
  107. playerRow = matrix.GetLength(0) - 1;
  108. }
  109. else
  110. {
  111. playerRow--;
  112. }
  113. }
  114. if (matrix[playerRow, playerCol] == 'F')
  115. {
  116. matrix[startRow, startCol] = '-';
  117. matrix[playerRow, playerCol] = 'f';
  118. Console.WriteLine("Player won!");
  119. PrintMatrix(matrix);
  120. return;
  121. }
  122.  
  123.  
  124. }
  125. else if (command == "right")
  126. {
  127. if (playerCol + 1 >= matrix.GetLength(1))
  128. {
  129. playerCol = 0;
  130. }
  131. else
  132. {
  133. playerCol++;
  134. }
  135. if (matrix[playerRow, playerCol] == 'B')
  136. {
  137. if (playerCol + 1 >= matrix.GetLength(1))
  138. {
  139. playerCol = 0;
  140. }
  141. else
  142. {
  143. playerCol ++;
  144. }
  145. }
  146. if (matrix[playerRow, playerCol] == 'T')
  147. {
  148. if (playerCol - 1 < 0)
  149. {
  150. playerCol = matrix.GetLength(1) - 1;
  151. }
  152. else
  153. {
  154. playerCol--;
  155. }
  156. }
  157. if (matrix[playerRow, playerCol] == 'F')
  158. {
  159.  
  160. matrix[startRow, startCol] = '-';
  161. matrix[playerRow, playerCol] = 'f';
  162. Console.WriteLine("Player won!");
  163. PrintMatrix(matrix);
  164. return;
  165. }
  166.  
  167. }
  168. else if (command == "left")
  169. {
  170. if (playerCol - 1 < 0)
  171. {
  172. playerCol = matrix.GetLength(1) - 1;
  173. }
  174. else
  175. {
  176. playerCol--;
  177. }
  178. if (matrix[playerRow, playerCol ] == 'B')
  179. {
  180. if (playerCol - 1 < 0)
  181. {
  182. playerCol = matrix.GetLength(1) - 1;
  183. }
  184. else
  185. {
  186. playerCol --;
  187. }
  188.  
  189.  
  190. }
  191. if (matrix[playerRow, playerCol] == 'T')
  192. {
  193. if (playerCol + 1 >= matrix.GetLength(1))
  194. {
  195. playerCol = 0;
  196. }
  197. else
  198. {
  199. playerCol++;
  200. }
  201. }
  202. if (matrix[playerRow, playerCol] == 'F')
  203. {
  204. matrix[startRow, startCol] = '-';
  205. matrix[playerRow, playerCol] = 'f';
  206. Console.WriteLine("Player won!");
  207. PrintMatrix(matrix);
  208. return;
  209. }
  210.  
  211. }
  212.  
  213. }
  214.  
  215. matrix[startRow, startCol] = '-';
  216. matrix[playerRow, playerCol] = 'f';
  217.  
  218. Console.WriteLine("Player lost!");
  219.  
  220. PrintMatrix(matrix);
  221. }
  222.  
  223. private static void PrintMatrix(char[,] matrix)
  224. {
  225. for (int row = 0; row < matrix.GetLength(0); row++)
  226. {
  227. for (int col = 0; col < matrix.GetLength(1); col++)
  228. {
  229. Console.Write(matrix[row, col]);
  230. }
  231.  
  232. Console.WriteLine();
  233. }
  234. }
  235. }
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement