Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace revolt
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- char[,] matrix = new char[n, n];
- int countOfCommands = int.Parse(Console.ReadLine());
- int cnt = 0;
- for (int col = 0; col < matrix.GetLength(0); col++)
- {
- string values = Console.ReadLine();
- for (int row = 0; row < matrix.GetLength(1); row++)
- {
- matrix[col, row] = values[row];
- }
- }
- int[] position = new int[2];
- for (int i = 0; i < countOfCommands; i++)
- {
- for (int col = 0; col < matrix.GetLength(0); col++)
- {
- for (int row = 0; row < matrix.GetLength(1); row++)
- {
- if (matrix[col, row] == 'f')
- {
- string command = Console.ReadLine();
- cnt++;
- position[0] = col;
- position[1] = row;
- if (command == "up")
- {
- if (col == 0)
- {
- matrix[col, row] = '-';
- matrix[col + matrix.GetLength(0) - 1, row] = 'f';
- break;
- }
- matrix[col, row] = '-';
- if (matrix[col + 1, row] == 'F')
- {
- matrix[col + 1, row] = 'f';
- Console.WriteLine("Player won!");
- PrintMatrix(matrix);
- return;
- }
- else if (matrix[col - 1, row] == 'T')
- {
- matrix[col, row] = 'f';
- }
- else if (matrix[col - 1, row] == 'B')
- {
- if (col - 2 >= 0)
- {
- matrix[col + 2, row] = 'f';
- }
- }
- else
- {
- if (col - 1 >= 0)
- {
- matrix[col - 1, row] = 'f';
- }
- }
- if (countOfCommands == cnt)
- {
- Console.WriteLine("Player lost!");
- PrintMatrix(matrix);
- }
- }
- else if (command == "down")
- {
- if (col == matrix.GetLength(0))
- {
- matrix[col, row] = '-';
- matrix[matrix.GetLength(0) - 1, row] = 'f';
- }
- matrix[col, row] = '-';
- if (matrix[col + 1, row] == 'F')
- {
- matrix[col + 1, row] = 'f';
- Console.WriteLine("Player won!");
- PrintMatrix(matrix);
- return;
- }
- else if (matrix[col - 1, row] == 'T')
- {
- matrix[col, row] = 'f';
- }
- else if (matrix[col + 1, row] == 'B')
- {
- if (col >= matrix.GetLength(0))
- {
- matrix[col + 2, row] = 'f';
- }
- }
- else
- {
- matrix[col - 1, row] = 'f';
- }
- if (countOfCommands == cnt)
- {
- Console.WriteLine("Player lost!");
- PrintMatrix(matrix);
- }
- }
- else if (command == "left")
- {
- if (row == 0)
- {
- matrix[col, row] = '-';
- matrix[col, row + matrix.GetLength(1) - 1] = 'f';
- }
- matrix[col, row] = '-';
- if (matrix[col, row - 1] == 'F')
- {
- matrix[col, row - 1] = 'f';
- Console.WriteLine("Player won!");
- PrintMatrix(matrix);
- return;
- }
- else if (matrix[col, row - 1] == 'T')
- {
- matrix[col, row] = 'f';
- }
- else if (matrix[col, row - 1] == 'B')
- {
- if (row - 1 >= 0)
- {
- matrix[col, row - 2] = 'f';
- }
- }
- else
- {
- if (row - 1 >= 0)
- {
- matrix[col, row - 1] = 'f';
- }
- }
- if (countOfCommands == cnt)
- {
- Console.WriteLine("Player lost!");
- PrintMatrix(matrix);
- }
- }
- else if (command == "right")
- {
- if (row == matrix.GetLength(1))
- {
- matrix[col, row] = '-';
- matrix[col, row - matrix.GetLength(1) - 1] = 'f';
- }
- matrix[col, row] = '-';
- if (matrix[col, row + 1] == 'F')
- {
- matrix[col, row + 1] = 'f';
- Console.WriteLine("Player won!");
- PrintMatrix(matrix);
- return;
- }
- else if (matrix[col, row + 1] == 'T')
- {
- matrix[col, row] = 'f';
- }
- else if (matrix[col, row + 1] == 'B')
- {
- if (row + 2 <= matrix.GetLength(1))
- {
- matrix[col, row + 2] = 'f';
- }
- }
- else
- {
- matrix[col + 1, row] = 'f';
- }
- if (countOfCommands == cnt)
- {
- Console.WriteLine("Player lost!");
- PrintMatrix(matrix);
- }
- }
- }
- }
- }
- }
- }
- private static void PrintMatrix(char[,] matrix)
- {
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- Console.Write(matrix[i, j]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement