Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ReVolt
- {
- class Program
- {
- static int N;
- static char[][] matrix;
- static int currentRow;
- static int currentCol;
- static void Main(string[] args)
- {
- N = int.Parse(Console.ReadLine());
- matrix = new char[N][];
- int countOfCommands = int.Parse(Console.ReadLine());
- for (int i = 0; i < N; i++)
- {
- var line = Console.ReadLine();
- matrix[i] = line.ToCharArray();
- }
- for (int row = 0; row < N; row++)
- {
- for (int col = 0; col < matrix[row].Length; col++)
- {
- if (matrix[row][col] == 'f')
- {
- currentRow = row;
- currentCol = col;
- }
- }
- }
- bool playerWon = false;
- for (int i = 0; i < countOfCommands; i++)
- {
- var command = Console.ReadLine();
- matrix[currentRow][currentCol] = '-';
- Move(command);
- switch (matrix[currentRow][currentCol])
- {
- case 'B': Move(command);
- if (matrix[currentRow][currentCol] == 'F')
- {
- playerWon = true;
- matrix[currentRow][currentCol] = 'f';
- }
- break;
- case 'T': Move(BackDirection(command));
- break;
- case 'F':
- playerWon = true;
- matrix[currentRow][currentCol] = 'f';
- break;
- }
- if (playerWon)
- {
- break;
- }
- matrix[currentRow][currentCol] = 'f';
- }
- if (playerWon) Console.WriteLine("Player won!");
- else Console.WriteLine("Player lost!");
- foreach (var row in matrix)
- {
- Console.WriteLine(string.Join("",row));
- }
- }
- static void Move(string command)
- {
- switch(command)
- {
- case "up": currentRow--;
- if (currentRow<0)
- {
- currentRow = N - 1;
- }
- break;
- case "down": currentRow++;
- if (currentRow==N)
- {
- currentRow = 0;
- }
- break;
- case "left": currentCol--;
- if (currentCol<0)
- {
- currentCol = N-1;
- }
- break;
- case "right": currentCol++;
- if (currentCol==N)
- {
- currentCol = 0;
- }
- break;
- }
- }
- static string BackDirection(string direction)
- {
- switch (direction)
- {
- case "up": return "down";
- case "down": return "up";
- case "left": return "right";
- case "right": return "left";
- default: return null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement