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