Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Re_Volt_AdvancedExam_22Feb20
- {
- class Program
- {
- static void Main(string[] args)
- {
- //int n = int.Parse(Console.ReadLine());
- //int countCommand = int.Parse(Console.ReadLine());
- //int[,] matrix = new int[n, n];
- //var playerRow = 0;
- //var playerCol = 0;
- //bool isWon = false;
- //for (int row = 0; row < matrix.GetLength(0); row++)
- //{
- // var currentRow = Console.ReadLine();
- // for (int col = 0; col < matrix.GetLength(1); col++)
- // {
- // matrix[row, col] = currentRow[col];
- // if (matrix[row, col] == 'f')
- // {
- // playerRow = 0;
- // playerCol = 0;
- // }
- // }
- //}
- //for (int i = 0; i < countCommand; i++)
- //{
- // string command = Console.ReadLine();
- // if (command == "up")
- // {
- // if (playerRow - 1 >= 0)
- // {
- // playerRow--;
- // var symbol = matrix[playerRow, playerCol];
- // if (symbol == 'F')
- // {
- // matrix[playerRow, playerCol] = 'f';
- // isWon = true;
- // break;
- // }
- // else if (symbol == 'B')
- // {
- // playerRow++;
- // matrix[playerRow, playerCol] = 'f';
- // matrix[playerRow + 1 + 1, playerCol] = '-';
- // }
- // else if (symbol == 'T')
- // {
- // playerRow--;
- // matrix[playerRow, playerCol] = 'f';
- // matrix[playerRow + 1, playerCol] = '-'; // If it's a trap??!!
- // }
- // }
- // else // if (playerRow < 0)
- // {
- // matrix[playerRow, playerCol] = '-';
- // playerRow = matrix.GetLength(0) - 1;
- // matrix[playerRow, playerCol] = 'f';
- // }
- // }
- // else if (command == "down")
- // {
- // if (playerRow + 1 < n)
- // {
- // playerRow++;
- // var symbol = matrix[playerRow, playerCol];
- // if (symbol == 'F')
- // {
- // matrix[playerRow, playerCol] = 'f';
- // isWon = true;
- // break;
- // }
- // else if (symbol == 'B')
- // {
- // playerRow++;
- // matrix[playerRow, playerCol] = 'f';
- // matrix[playerRow + 1 + 1, playerCol] = '-';
- // }
- // else if (symbol == 'T')
- // {
- // playerRow--;
- // matrix[playerRow, playerCol] = 'f';
- // matrix[playerRow + 1, playerCol] = '-'; // If it's a trap??!!
- // }
- // }
- // else // if (playerRow > n)
- // {
- // matrix[playerRow, playerCol] = '-';
- // playerRow = matrix.GetLength(0) - 1;
- // matrix[playerRow, playerCol] = 'f';
- // }
- // }
- // else if (command == "left")
- // {
- // }
- // else if (command == "right")
- // {
- // }
- //}
- int sizeN = int.Parse(Console.ReadLine());
- int countOfCommands = int.Parse(Console.ReadLine());
- var matrix = new char[sizeN, sizeN];
- var rowCheck = 0;
- var colCheck = 0;
- bool isWon = false;
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- string currentRow = Console.ReadLine();
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- matrix[row, col] = currentRow[col];
- if (matrix[row, col] == 'f')
- {
- rowCheck = row;
- colCheck = col;
- }
- }
- }
- for (int i = 0; i < countOfCommands; i++)
- {
- string command = Console.ReadLine();
- matrix[rowCheck, colCheck] = '-';
- if (command == "up")
- {
- if (rowCheck - 1 >= 0)
- {
- rowCheck--;
- }
- else
- {
- rowCheck = matrix.GetLength(0) - 1;
- }
- while (matrix[rowCheck, colCheck] != '-' && matrix[rowCheck, colCheck] != 'F')
- {
- if (matrix[rowCheck, colCheck] == 'T')
- {
- rowCheck++;
- }
- else if (matrix[rowCheck, colCheck] == 'B')
- {
- rowCheck--;
- }
- if (rowCheck < 0)
- {
- rowCheck = matrix.GetLength(0) - 1;
- }
- }
- if (matrix[rowCheck, colCheck] == 'F')
- {
- isWon = true;
- break;
- }
- matrix[rowCheck, colCheck] = 'f';
- }
- else if (command == "down")
- {
- if (rowCheck + 1 < matrix.GetLength(0))
- {
- rowCheck++;
- }
- else
- {
- rowCheck = 0;
- }
- while (matrix[rowCheck, colCheck] != '-' && matrix[rowCheck, colCheck] != 'F')
- {
- if (matrix[rowCheck, colCheck] == 'T')
- {
- rowCheck--;
- }
- else if (matrix[rowCheck, colCheck] == 'B')
- {
- rowCheck++;
- }
- if (rowCheck == matrix.GetLength(0))
- {
- rowCheck = 0;
- }
- }
- if (matrix[rowCheck, colCheck] == 'F')
- {
- isWon = true;
- break;
- }
- matrix[rowCheck, colCheck] = 'f';
- }
- else if (command == "left")
- {
- if (colCheck - 1 >= 0)
- {
- colCheck--;
- }
- else
- {
- colCheck = matrix.GetLength(1) - 1;
- }
- while (matrix[rowCheck, colCheck] != '-' && matrix[rowCheck, colCheck] != 'F')
- {
- if (matrix[rowCheck, colCheck] == 'T')
- {
- colCheck++;
- }
- else if (matrix[rowCheck, colCheck] == 'B')
- {
- colCheck--;
- }
- if (colCheck < 0)
- {
- colCheck = matrix.GetLength(1) - 1;
- }
- }
- if (matrix[rowCheck, colCheck] == 'F')
- {
- isWon = true;
- break;
- }
- matrix[rowCheck, colCheck] = 'f';
- }
- else if (command == "right")
- {
- if (colCheck + 1 < matrix.GetLength(1))
- {
- colCheck++;
- }
- else
- {
- colCheck = 0;
- }
- while (matrix[rowCheck, colCheck] != '-' && matrix[rowCheck, colCheck] != 'F')
- {
- if (matrix[rowCheck, colCheck] == 'T')
- {
- colCheck--;
- }
- else if (matrix[rowCheck, colCheck] == 'B')
- {
- colCheck++;
- }
- if (colCheck == matrix.GetLength(1))
- {
- colCheck = 0;
- }
- }
- if (matrix[rowCheck, colCheck] == 'F')
- {
- isWon = true;
- break;
- }
- matrix[rowCheck, colCheck] = 'f';
- }
- }
- if (isWon)
- {
- matrix[rowCheck, colCheck] = 'f';
- Console.WriteLine("Player won!");
- }
- else
- {
- Console.WriteLine("Player lost!");
- }
- MatrixPrint(matrix);
- }
- static void MatrixPrint(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