Advertisement
Guest User

Untitled

a guest
Jun 4th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _02_Tron_Racers
  4. {
  5. class Program
  6. {
  7. static char[,] matrix;
  8. static int firstPlayerRow;
  9. static int secondPlayerRow;
  10.  
  11. static int firstPlayerCol;
  12. static int secondPlayerCol;
  13. static void Main(string[] args)
  14. {
  15. int n = int.Parse(Console.ReadLine());
  16. matrix = new char[n, n];
  17.  
  18. firstPlayerRow = 0;
  19. secondPlayerRow = 0;
  20.  
  21. firstPlayerCol = 0;
  22. secondPlayerCol = 0;
  23.  
  24. Initialize(n);
  25.  
  26. while (true)
  27. {
  28. var commands = Console.ReadLine()
  29. .Split(" ", StringSplitOptions.RemoveEmptyEntries);
  30.  
  31. var commandFirstPlayer = commands[0];
  32. var commandSecondPlayer = commands[1];
  33.  
  34. if (commandFirstPlayer == "up")
  35. {
  36. firstPlayerRow --;
  37.  
  38. if (firstPlayerRow < 0)
  39. {
  40. firstPlayerRow = matrix.GetLength(0)-1;
  41. }
  42. }
  43.  
  44. else if (commandFirstPlayer == "down")
  45. {
  46. firstPlayerRow++;
  47.  
  48. if (firstPlayerRow > matrix.GetLength(0) - 1)
  49. {
  50. firstPlayerRow = 0;
  51. }
  52. }
  53.  
  54. else if (commandFirstPlayer == "left")
  55. {
  56. firstPlayerCol --;
  57. if (firstPlayerCol < 0)
  58. {
  59. firstPlayerCol = matrix.GetLength(1)-1;
  60. }
  61. }
  62.  
  63. else if (commandFirstPlayer == "right")
  64. {
  65. firstPlayerCol ++;
  66. if (firstPlayerCol > matrix.GetLength(1) - 1)
  67. {
  68. firstPlayerCol = 0;
  69. }
  70. }
  71.  
  72. if (matrix[firstPlayerRow, firstPlayerCol] == 's')
  73. {
  74. matrix[firstPlayerRow, firstPlayerCol] = 'x';
  75. End();
  76. }
  77. else
  78. {
  79. matrix[firstPlayerRow, firstPlayerCol] = 'f';
  80. }
  81.  
  82.  
  83.  
  84.  
  85. if (commandSecondPlayer == "up")
  86. {
  87. secondPlayerRow --;
  88.  
  89. if (secondPlayerRow < 0)
  90. {
  91. secondPlayerRow = matrix.GetLength(0)-1;
  92. }
  93. }
  94.  
  95. else if (commandSecondPlayer == "down")
  96. {
  97. secondPlayerRow ++;
  98.  
  99. if (secondPlayerRow > matrix.GetLength(0) - 1)
  100. {
  101. secondPlayerRow = 0;
  102. }
  103. }
  104.  
  105. else if (commandSecondPlayer == "left")
  106. {
  107. secondPlayerCol --;
  108. if (secondPlayerCol < 0)
  109. {
  110. secondPlayerCol = matrix.GetLength(1)-1;
  111. }
  112. }
  113.  
  114. else if (commandSecondPlayer == "right")
  115. {
  116. secondPlayerCol ++;
  117. if (secondPlayerCol > matrix.GetLength(1) - 1)
  118. {
  119. secondPlayerCol = 0;
  120. }
  121. }
  122.  
  123. if (matrix[secondPlayerRow, secondPlayerCol] == 'f')
  124. {
  125. matrix[secondPlayerRow, secondPlayerCol] = 'x';
  126. End();
  127. }
  128. else
  129. {
  130. matrix[secondPlayerRow, secondPlayerCol] = 's';
  131. }
  132.  
  133. }
  134.  
  135.  
  136. }
  137. private static void Initialize(int n)
  138. {
  139. for (int row = 0; row < n; row++)
  140. {
  141. string input = Console.ReadLine();
  142. for (int col = 0; col < n; col++)
  143. {
  144. matrix[row, col] = input[col];
  145. if (matrix[row, col] == 'f')
  146. {
  147. firstPlayerRow = row;
  148. firstPlayerCol = col;
  149. }
  150. else if (matrix[row, col] == 's')
  151. {
  152. secondPlayerRow = row;
  153. secondPlayerCol = col;
  154. }
  155.  
  156. }
  157. }
  158. }
  159.  
  160. private static void End()
  161. {
  162. for (int row = 0; row < matrix.GetLength(0); row++)
  163. {
  164. for (int col = 0; col < matrix.GetLength(1); col++)
  165. {
  166. Console.Write(matrix[row, col]);
  167. }
  168. Console.WriteLine();
  169. }
  170. Environment.Exit(0);
  171. }
  172.  
  173. }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement