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());
- int countCommands = int.Parse(Console.ReadLine());
- char[,] matrix = new char[n,n];
- int pRows = 0;
- int pCols = 0;
- bool won = false;
- for (int rows = 0; rows < n; rows++)
- {
- string input = Console.ReadLine();
- for (int cols = 0; cols < n; cols++)
- {
- matrix[rows, cols] = input[cols];
- if (matrix[rows,cols] == 'f')
- {
- pRows = rows;
- pCols = cols;
- }
- }
- }
- matrix[pRows, pCols] = '-';
- for (int i = 0; i < countCommands; i++)
- {
- string command = Console.ReadLine();
- if (command == "up")
- {
- pRows--;
- if (pRows < 0)
- {
- pRows = n - 1;
- }
- while (matrix[pRows,pCols] != '-' && matrix[pRows,pCols] != 'F')
- {
- if (matrix[pRows,pCols] == 'B')
- {
- pRows--;
- }
- else if (matrix[pRows, pCols] == 'T')
- {
- pRows++;
- }
- if (pRows < 0)
- {
- pRows = n - 1;
- }
- }
- if (matrix[pRows,pCols] == 'F')
- {
- won = true;
- break;
- }
- }
- if (command == "left")
- {
- pCols--;
- if (pCols < 0)
- {
- pCols = n - 1;
- }
- while (matrix[pRows, pCols] != '-' && matrix[pRows, pCols] != 'F')
- {
- if (matrix[pRows, pCols] == 'B')
- {
- pCols--;
- }
- else if (matrix[pRows, pCols] == 'T')
- {
- pCols++;
- }
- if (pCols < 0)
- {
- pCols = n - 1;
- }
- }
- if (matrix[pRows, pCols] == 'F')
- {
- won = true;
- break;
- }
- }
- if (command == "right")
- {
- pCols++;
- if (pCols > n -1)
- {
- pCols = 0;
- }
- while (matrix[pRows, pCols] != '-' && matrix[pRows, pCols] != 'F')
- {
- if (matrix[pRows, pCols] == 'B')
- {
- pCols++;
- }
- else if (matrix[pRows, pCols] == 'T')
- {
- pCols--;
- }
- if (pCols > n - 1)
- {
- pCols = 0;
- }
- }
- if (matrix[pRows, pCols] == 'F')
- {
- won = true;
- break;
- }
- }
- if (command == "down")
- {
- pRows++;
- if (pRows > n - 1)
- {
- pRows = 0;
- }
- while (matrix[pRows, pCols] != '-' && matrix[pRows, pCols] != 'F')
- {
- if (matrix[pRows, pCols] == 'B')
- {
- pRows++;
- }
- else if (matrix[pRows, pCols] == 'T')
- {
- pRows--;
- }
- if (pRows > n - 1)
- {
- pRows = 0;
- }
- }
- if (matrix[pRows, pCols] == 'F')
- {
- won = true;
- break;
- }
- }
- }
- matrix[pRows, pCols] = 'f';
- if (won)
- {
- Console.WriteLine("Player won!");
- }
- else
- {
- Console.WriteLine("Player lost!");
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write(matrix[i,j]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement