Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Revolt_Second_Attempt
- {
- class StartUp
- {
- static void Main(string[] args)
- {
- var size = int.Parse(Console.ReadLine());
- var commands = int.Parse(Console.ReadLine());
- var matrix = new char[size, size];
- var playerRow = 0;
- var playerCol = 0;
- for (int row = 0; row < size; row++)
- {
- var curRow = Console.ReadLine()
- .ToCharArray();
- for (int col = 0; col < size; col++)
- {
- matrix[row, col] = curRow[col];
- if (matrix[row, col] == 'f')
- {
- playerRow = row;
- playerCol = col;
- matrix[row, col] = '-';
- }
- }
- }
- bool IsAWin = false;
- for (int i = 0; i < commands; i++)
- {
- var direction = Console.ReadLine();
- if (direction == "up")
- {
- playerRow -= 1;
- if (playerRow < 0)
- {
- playerRow = size - 1;
- }
- if (matrix[playerRow, playerCol] == 'B')
- {
- playerRow -= 1;
- if (playerRow < 0)
- {
- playerRow = size - 1;
- }
- }
- else if (matrix[playerRow, playerCol] == 'T')
- {
- playerRow += 1;
- if (playerRow > size - 1)
- {
- playerRow = 0;
- }
- }
- if (matrix[playerRow, playerCol] == 'F')
- {
- matrix[playerRow, playerCol] = 'f';
- IsAWin = true;
- break;
- }
- }
- else if (direction == "down")
- {
- playerRow += 1;
- if (playerRow > size - 1)
- {
- playerRow = 0;
- }
- if (matrix[playerRow, playerCol] == 'B')
- {
- playerRow += 1;
- if (playerRow > size - 1)
- {
- playerRow = 0;
- }
- }
- else if (matrix[playerRow, playerCol] == 'T')
- {
- playerRow -= 1;
- if (playerRow < 0)
- {
- playerRow = size - 1;
- }
- }
- if (matrix[playerRow, playerCol] == 'F')
- {
- matrix[playerRow, playerCol] = 'f';
- IsAWin = true;
- break;
- }
- }
- else if (direction == "left")
- {
- playerCol -= 1;
- if (playerCol < 0)
- {
- playerCol = size - 1;
- }
- if (matrix[playerRow, playerCol] == 'B')
- {
- playerCol -= 1;
- if (playerCol < 0)
- {
- playerCol = size - 1;
- }
- }
- else if (matrix[playerRow, playerCol] == 'T')
- {
- playerCol += 1;
- if (playerCol > size - 1)
- {
- playerCol = 0;
- }
- }
- if (matrix[playerRow, playerCol] == 'F')
- {
- matrix[playerRow, playerCol] = 'f';
- IsAWin = true;
- break;
- }
- }
- else if (direction == "right")
- {
- playerCol += 1;
- if (playerCol > size - 1)
- {
- playerCol = 0;
- }
- if (matrix[playerRow, playerCol] == 'B')
- {
- playerCol += 1;
- if (playerCol > size - 1)
- {
- playerCol = 0;
- }
- }
- else if (matrix[playerRow, playerCol] == 'T')
- {
- playerCol -= 1;
- if (playerCol < 0)
- {
- playerCol = size - 1;
- }
- }
- if (matrix[playerRow, playerCol] == 'F')
- {
- matrix[playerRow, playerCol] = 'f';
- IsAWin = true;
- break;
- }
- }
- }
- if (IsAWin)
- {
- Console.WriteLine("Player won!");
- PrintMatrix(size, matrix);
- }
- else
- {
- Console.WriteLine("Player lost!");
- matrix[playerRow, playerCol] = 'f';
- PrintMatrix(size, matrix);
- }
- }
- private static void PrintMatrix(int size, char[,] matrix)
- {
- for (int row = 0; row < size; row++)
- {
- for (int col = 0; col < size; col++)
- {
- Console.Write(matrix[row, col]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement