Advertisement
Guest User

Untitled

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