Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Tron_Racers
- {
- class Program
- {
- static void Main(string[] args)
- {
- int sizeOfMatrix = int.Parse(Console.ReadLine());
- var matrix = new char[sizeOfMatrix][];
- int FirstPlayerRow = 0;
- int FirstPlayerCol = 0;
- int SecondPlayerRow = 0;
- int SecondPlayerCol = 0;
- for (int row = 0; row < matrix.Length; row++)
- {
- string currentRow = Console.ReadLine();
- int length = currentRow.Length;
- matrix[row] = new char[length];
- for (int col = 0; col < matrix[row].Length; col++)
- {
- matrix[row][col] = currentRow[col];
- if (currentRow[col] == 'f')
- {
- FirstPlayerRow = row;
- FirstPlayerCol = col;
- }
- else if (currentRow[col] == 's')
- {
- SecondPlayerRow = row;
- SecondPlayerCol = col;
- }
- }
- }
- while (true)
- {
- var commands = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string firstDirection = commands[0];
- string secondDirection = commands[1];
- if (firstDirection == "up")
- {
- if (FirstPlayerRow - 1 >= 0)
- {
- FirstPlayerRow--;
- if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
- }
- else
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
- break;
- }
- }
- else if (FirstPlayerRow - 1 < 0)
- {
- FirstPlayerRow = matrix.Length - 1;
- if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
- }
- else
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
- break;
- }
- }
- }
- else if (firstDirection == "down")
- {
- if (FirstPlayerRow + 1 < matrix.Length)
- {
- FirstPlayerRow++;
- if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
- }
- else
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
- break;
- }
- }
- else if (FirstPlayerRow + 1 >= matrix.Length)
- {
- FirstPlayerRow = 0;
- if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
- }
- else
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
- break;
- }
- }
- }
- else if (firstDirection == "right")
- {
- if (FirstPlayerCol + 1 < matrix[FirstPlayerRow].Length)
- {
- FirstPlayerCol++;
- if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
- }
- else
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
- break;
- }
- }
- else if (FirstPlayerCol + 1 >= matrix.Length)
- {
- FirstPlayerCol = 0;
- if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
- }
- else
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
- break;
- }
- }
- }
- else if (firstDirection == "left")
- {
- if (FirstPlayerCol - 1 >= 0)
- {
- FirstPlayerCol--;
- if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
- }
- else
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
- break;
- }
- }
- else if (FirstPlayerCol - 1 < 0)
- {
- FirstPlayerCol = matrix[FirstPlayerRow].Length - 1;
- if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
- }
- else
- {
- matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
- break;
- }
- }
- }
- if (secondDirection == "up")
- {
- if (SecondPlayerRow - 1 >= 0)
- {
- SecondPlayerRow--;
- if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 's';
- }
- else
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
- break;
- }
- }
- else if (SecondPlayerRow - 1 < 0)
- {
- SecondPlayerRow = matrix.Length - 1;
- if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 's';
- }
- else
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
- break;
- }
- }
- }
- else if (secondDirection == "down")
- {
- if (SecondPlayerRow + 1 < matrix.Length)
- {
- SecondPlayerRow++;
- if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 's';
- }
- else
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
- break;
- }
- }
- else if (SecondPlayerRow + 1 >= matrix.Length)
- {
- SecondPlayerRow = 0;
- if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 's';
- }
- else
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
- break;
- }
- }
- }
- else if (secondDirection == "right")
- {
- if (SecondPlayerCol + 1 < matrix[SecondPlayerRow].Length)
- {
- SecondPlayerCol++;
- if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 's';
- }
- else
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
- break;
- }
- }
- else if (SecondPlayerCol + 1 >= matrix.Length)
- {
- SecondPlayerCol = 0;
- if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 's';
- }
- else
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
- break;
- }
- }
- }
- else if (secondDirection == "left")
- {
- if (SecondPlayerCol - 1 >= 0)
- {
- SecondPlayerCol--;
- if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 's';
- }
- else
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
- break;
- }
- }
- else if (SecondPlayerCol - 1 < 0)
- {
- SecondPlayerCol = matrix[SecondPlayerRow].Length - 1;
- if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 's';
- }
- else
- {
- matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
- break;
- }
- }
- }
- }
- PrintMatrix(matrix);
- }
- private static void PrintMatrix(char[][] matrix)
- {
- for (int row = 0; row < matrix.Length; row++)
- {
- for (int col = 0; col < matrix[row].Length; col++)
- {
- Console.Write(matrix[row][col]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement