Advertisement
Guest User

Untitled

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