Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _02_Tron_Racers
- {
- class Program
- {
- static char[,] matrix;
- static int firstPlayerRow;
- static int secondPlayerRow;
- static int firstPlayerCol;
- static int secondPlayerCol;
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- matrix = new char[n, n];
- firstPlayerRow = 0;
- secondPlayerRow = 0;
- firstPlayerCol = 0;
- secondPlayerCol = 0;
- Initialize(n);
- while (true)
- {
- var commands = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries);
- var commandFirstPlayer = commands[0];
- var commandSecondPlayer = commands[1];
- if (commandFirstPlayer == "up")
- {
- firstPlayerRow --;
- if (firstPlayerRow < 0)
- {
- firstPlayerRow = matrix.GetLength(0)-1;
- }
- }
- else if (commandFirstPlayer == "down")
- {
- firstPlayerRow++;
- if (firstPlayerRow > matrix.GetLength(0) - 1)
- {
- firstPlayerRow = 0;
- }
- }
- else if (commandFirstPlayer == "left")
- {
- firstPlayerCol --;
- if (firstPlayerCol < 0)
- {
- firstPlayerCol = matrix.GetLength(1)-1;
- }
- }
- else if (commandFirstPlayer == "right")
- {
- firstPlayerCol ++;
- if (firstPlayerCol > matrix.GetLength(1) - 1)
- {
- firstPlayerCol = 0;
- }
- }
- if (matrix[firstPlayerRow, firstPlayerCol] == 's')
- {
- matrix[firstPlayerRow, firstPlayerCol] = 'x';
- End();
- }
- else
- {
- matrix[firstPlayerRow, firstPlayerCol] = 'f';
- }
- if (commandSecondPlayer == "up")
- {
- secondPlayerRow --;
- if (secondPlayerRow < 0)
- {
- secondPlayerRow = matrix.GetLength(0)-1;
- }
- }
- else if (commandSecondPlayer == "down")
- {
- secondPlayerRow ++;
- if (secondPlayerRow > matrix.GetLength(0) - 1)
- {
- secondPlayerRow = 0;
- }
- }
- else if (commandSecondPlayer == "left")
- {
- secondPlayerCol --;
- if (secondPlayerCol < 0)
- {
- secondPlayerCol = matrix.GetLength(1)-1;
- }
- }
- else if (commandSecondPlayer == "right")
- {
- secondPlayerCol ++;
- if (secondPlayerCol > matrix.GetLength(1) - 1)
- {
- secondPlayerCol = 0;
- }
- }
- if (matrix[secondPlayerRow, secondPlayerCol] == 'f')
- {
- matrix[secondPlayerRow, secondPlayerCol] = 'x';
- End();
- }
- else
- {
- matrix[secondPlayerRow, secondPlayerCol] = 's';
- }
- }
- }
- private static void Initialize(int n)
- {
- for (int row = 0; row < n; row++)
- {
- string input = Console.ReadLine();
- for (int col = 0; col < n; col++)
- {
- matrix[row, col] = input[col];
- if (matrix[row, col] == 'f')
- {
- firstPlayerRow = row;
- firstPlayerCol = col;
- }
- else if (matrix[row, col] == 's')
- {
- secondPlayerRow = row;
- secondPlayerCol = col;
- }
- }
- }
- }
- private static void End()
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- Console.Write(matrix[row, col]);
- }
- Console.WriteLine();
- }
- Environment.Exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement