Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- class Program
- {
- static int stephenRow;
- static int stephenCol;
- static void Main(string[] args)
- {
- int sizeOfMatrix = int.Parse(Console.ReadLine());
- char[][] galaxy = new char[sizeOfMatrix][];
- FillMatrix(galaxy);
- int energy = 0;
- FindStephen(galaxy);
- while (true)
- {
- string direction = Console.ReadLine();
- if (direction == "end")
- {
- break;
- }
- if (direction == "up")
- {
- if (stephenRow - 1 >= 0)
- {
- stephenRow--;
- galaxy[stephenRow][stephenCol] = 'S';
- }
- else if (direction == "down")
- {
- if (stephenRow + 1 < galaxy.Length)
- {
- stephenRow++;
- }
- }
- else if (direction == "left")
- {
- if (stephenCol - 1 >= 0)
- {
- stephenCol--;
- }
- }
- else if (direction == "right")
- {
- if (stephenRow + 1 < galaxy[stephenRow].Length)
- {
- stephenCol++;
- }
- }
- char symbolOnNextStep = galaxy[stephenRow][stephenCol];
- if (symbolOnNextStep == '-')
- {
- galaxy[stephenRow][stephenCol] = 'S';
- }
- }
- PrintMatrix(galaxy);
- }
- }
- private static void PrintMatrix(char[][] galaxy)
- {
- for (int row = 0; row < galaxy.Length; row++)
- {
- Console.WriteLine(string.Join("", galaxy[row]));
- }
- }
- private static void FindStephen(char[][] galaxy)
- {
- for (int row = 0; row < galaxy.Length; row++)
- {
- for (int col = 0; col < galaxy[row].Length; col++)
- {
- if (galaxy[row][col] == 'S')
- {
- stephenRow = row;
- stephenCol = col;
- }
- }
- }
- }
- private static void FillMatrix(char[][] galaxy)
- {
- for (int row = 0; row < galaxy.Length; row++)
- {
- var data = Console.ReadLine().ToCharArray();
- galaxy[row] = data;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement