Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _02._Tron_Racers
- {
- class Program
- {
- static void Main(string[] args)
- {
- int size = int.Parse(Console.ReadLine());
- char[,] matrix = new char[size, size];
- int Frow = 0;
- int Fcol = 0;
- int Srow = 0;
- int Scol = 0;
- int newRowF = 0;
- int newColF = 0;
- int newRowS = 0;
- int newColS = 0;
- for (int row = 0; row < size; row++)
- {
- string currRow = Console.ReadLine();
- for (int col = 0; col < size; col++)
- {
- if (currRow[col] == 'f')
- {
- Frow = row;
- Fcol = col;
- }
- else if (currRow[col] == 's')
- {
- Srow = row;
- Scol = col;
- }
- matrix[row, col] = currRow[col];
- }
- }
- while (true)
- {
- string[] command = Console.ReadLine().Split();
- string cmdF = command[0];
- string cmdS = command[1];
- if (cmdF == "up")
- {
- newRowF = Frow - 1;
- newColF = Fcol;
- if (newRowF < 0)
- {
- newRowF = size - 1;
- }
- if (matrix[newRowF, newColF] == 's')
- {
- matrix[newRowF, newColF] = 'x';
- break;
- }
- matrix[newRowF, newColF] = 'f';
- }
- if (cmdS == "up")
- {
- newRowS = Srow - 1;
- newColS = Scol;
- if (newRowS < 0)
- {
- newRowS = size - 1;
- }
- if (matrix[newRowS, newColS] == 'f')
- {
- matrix[newRowS, newColS] = 'x';
- break;
- }
- matrix[newRowS, newColS] = 's';
- }
- if (cmdF == "down")
- {
- newRowF = Frow + 1;
- newColF = Fcol;
- if (newRowF >= size)
- {
- newRowF = 0;
- }
- if (matrix[newRowF, newColF] == 's')
- {
- matrix[newRowF, newColF] = 'x';
- break;
- }
- matrix[newRowF, newColF] = 'f';
- }
- if (cmdS == "down")
- {
- newRowS = Srow + 1;
- newColS = Scol;
- if (newRowS >= size)
- {
- newRowS = 0;
- }
- if (matrix[newRowS, newColS] == 'f')
- {
- matrix[newRowS, newColS] = 'x';
- break;
- }
- matrix[newRowS, newColS] = 's';
- }
- if (cmdF == "left")
- {
- newRowF = Frow;
- newColF = Fcol - 1;
- if (newColF < 0)
- {
- newColF = size - 1;
- }
- if (matrix[newRowF, newColF] == 's')
- {
- matrix[newRowF, newColF] = 'x';
- break;
- }
- matrix[newRowF, newColF] = 'f';
- }
- if (cmdS == "left")
- {
- newRowS = Srow;
- newColS = Scol - 1;
- if (newRowS < 0)
- {
- newColS = size - 1;
- }
- if (matrix[newRowS, newColS] == 'f')
- {
- matrix[newRowS, newColS] = 'x';
- break;
- }
- matrix[newRowS, newColS] = 's';
- }
- if (cmdF == "right")
- {
- newRowF = Frow;
- newColF = Fcol + 1;
- if (newColF >= size)
- {
- newColF = 0;
- }
- if (matrix[newRowF, newColF] == 's')
- {
- matrix[newRowF, newColF] = 'x';
- break;
- }
- matrix[newRowF, newColF] = 'f';
- }
- if (cmdS == "right")
- {
- newRowS = Srow;
- newColS = Scol + 1;
- if (newRowS >= size)
- {
- newColS = 0;
- }
- if (matrix[newRowS, newColS] == 'f')
- {
- matrix[newRowS, newColS] = 'x';
- break;
- }
- matrix[newRowS, newColS] = 's';
- }
- Frow = newRowF;
- Fcol = newColF;
- Srow = newRowS;
- Scol = newColS;
- }
- for (int row = 0; row < size; row++)
- {
- for (int col = 0; col < size; col++)
- {
- Console.Write(matrix[row, col]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement