Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _02.Re_Volt
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int countOfCommands = int.Parse(Console.ReadLine());
- char[,] matrix = new char[n, n];
- int finishRow = 0;
- int finishCol = 0;
- int playerRow = 0;
- int playerCol = 0;
- bool isFinished = false;
- for (int row = 0; row < n; row++)
- {
- char[] currentRow = Console.ReadLine().ToCharArray();
- for (int col = 0; col < n; col++)
- {
- matrix[row, col] = currentRow[col];
- char symbol = matrix[row, col];
- if (symbol == 'f')
- {
- playerRow = row;
- playerCol = col;
- }
- if (symbol == 'F')
- {
- finishRow = row;
- finishCol = col;
- }
- }
- }
- for (int i = 0; i < countOfCommands; i++)
- {
- string command = Console.ReadLine();
- matrix[playerRow, playerCol] = '-';
- if (command == "up")
- {
- if (playerRow == 0) //invalid index
- {
- playerRow = n - 1;
- char nextStep = matrix[playerRow, playerCol];
- if (nextStep == 'B')
- {
- playerRow--;
- }
- else if (nextStep == 'T')
- {
- playerRow = 0;
- }
- else if (nextStep == 'F')
- {
- playerRow = finishRow;
- playerCol = finishCol;
- matrix[playerRow, playerCol] = 'f';
- isFinished = true;
- break;
- }
- }
- else
- {
- char nextStep = matrix[playerRow - 1, playerCol];
- if (nextStep == 'B')
- {
- playerRow--;
- playerRow--;
- }
- else if (nextStep == 'T')
- {
- playerRow--;
- playerRow++;
- }
- else if (nextStep == 'F')
- {
- playerRow = finishRow;
- playerCol = finishCol;
- matrix[playerRow, playerCol] = 'f';
- isFinished = true;
- break;
- }
- else
- {
- playerRow--;
- }
- }
- }
- else if (command == "down")
- {
- if (playerRow == n-1)
- {
- playerRow = 0;
- char nextStep = matrix[playerRow, playerCol];
- if (nextStep == 'B')
- {
- playerRow++;
- }
- else if (nextStep == 'T')
- {
- playerRow = n - 1;
- }
- else if (nextStep == 'F')
- {
- playerRow = finishRow;
- playerCol = finishCol;
- matrix[playerRow, playerCol] = 'f';
- isFinished = true;
- break;
- }
- }
- else
- {
- char nextStep = matrix[playerRow + 1, playerCol];
- if (nextStep == 'B')
- {
- playerRow++;
- playerRow++;
- }
- else if (nextStep == 'T')
- {
- playerRow--;
- playerRow++;
- }
- else if (nextStep == 'F')
- {
- playerRow = finishRow;
- playerCol = finishCol;
- matrix[playerRow, playerCol] = 'f';
- isFinished = true;
- break;
- }
- else
- {
- playerRow++;
- }
- }
- }
- else if (command == "left")
- {
- if (playerCol == 0)
- {
- playerCol = n - 1;
- char nextStep = matrix[playerRow, playerCol];
- if (nextStep == 'B')
- {
- playerCol--;
- }
- else if (nextStep == 'T')
- {
- playerCol = 0;
- }
- else if (nextStep == 'F')
- {
- playerRow = finishRow;
- playerCol = finishCol;
- matrix[playerRow, playerCol] = 'f';
- isFinished = true;
- break;
- }
- }
- else
- {
- char nextStep = matrix[playerRow, playerCol - 1];
- if (nextStep == 'B')
- {
- playerCol--;
- playerCol--;
- }
- else if (nextStep == 'T')
- {
- playerCol--;
- playerCol++;
- }
- else if (nextStep == 'F')
- {
- playerRow = finishRow;
- playerCol = finishCol;
- matrix[playerRow, playerCol] = 'f';
- isFinished = true;
- break;
- }
- else
- {
- playerCol--;
- }
- }
- }
- else if (command == "right")
- {
- if (playerCol == n-1)
- {
- playerCol = 0;
- char nextStep = matrix[playerRow, playerCol];
- if (nextStep == 'B')
- {
- playerCol++;
- playerCol++;
- }
- else if (nextStep == 'T')
- {
- playerCol = n - 1; ;
- }
- else if (nextStep == 'F')
- {
- playerRow = finishRow;
- playerCol = finishCol;
- matrix[playerRow, playerCol] = 'f';
- isFinished = true;
- break;
- }
- }
- else
- {
- char nextStep = matrix[playerRow, playerCol + 1];
- if (nextStep == 'B')
- {
- playerCol--;
- }
- else if (nextStep == 'T')
- {
- playerCol++;
- playerCol--;
- }
- else if (nextStep == 'F')
- {
- playerRow = finishRow;
- playerCol = finishCol;
- matrix[playerRow, playerCol] = 'f';
- isFinished = true;
- break;
- }
- else
- {
- playerCol++;
- }
- }
- }
- }
- if (isFinished)
- {
- Console.WriteLine("Player won!");
- }
- else
- {
- matrix[playerRow, playerCol] = 'f';
- Console.WriteLine("Player lost!");
- }
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- Console.Write(matrix[row, col]);
- }
- Console.WriteLine();
- }
- }
- private static bool IndexIsValid(int row, int col, int n)
- {
- return row >= 0 &&
- row < n &&
- col >= 0 &&
- col < n;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement