Advertisement
Guest User

Untitled

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