Advertisement
svetlyoek

Untitled

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