Advertisement
Guest User

Untitled

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