Advertisement
bullit3189

Tron Racers

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