Advertisement
Guest User

Untitled

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