Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace SpaceStationEstablishment
- {
- class Program
- {
- static void Main(string[] args)
- {
- var row = int.Parse(Console.ReadLine());
- var matrix = new char[row][];
- var playerRow = -1;
- var playerCol = -1;
- for (int i = 0; i < row; i++)
- {
- var col = Console.ReadLine().ToCharArray();
- matrix[i] = col;
- if (matrix[i].Contains('S'))
- {
- playerRow = i;
- playerCol = Array.IndexOf(matrix[i], 'S');
- }
- }
- var energy = 0;
- while (energy < 50)
- {
- var command = Console.ReadLine();
- matrix[playerRow][playerCol] = '-';
- switch (command)
- {
- case "up": playerRow--; break;
- case "down": playerRow++; break;
- case "left": playerCol--; break;
- case "right": playerCol++; break;
- }
- if (IsInMatrix(matrix, playerRow, playerCol))
- {
- if (Char.IsDigit(matrix[playerRow][playerCol]))
- {
- energy += int.Parse(matrix[playerRow][playerCol].ToString());
- }
- else if (matrix[playerRow][playerCol] == 'O')
- {
- matrix[playerRow][playerCol] = '-';
- for (int i = 0; i < row; i++)
- {
- if (matrix[i].Contains('O'))
- {
- playerRow = i;
- playerCol = Array.IndexOf(matrix[i], 'O');
- }
- }
- }
- matrix[playerRow][playerCol] = 'S';
- }
- else
- {
- Console.WriteLine("Bad news, the spaceship went to the void.");
- Console.WriteLine($"Star power collected: {energy}");
- PrintMatrix(matrix);
- return;
- }
- }
- Console.WriteLine("Good news! Stephen succeeded in collecting enough star power!");
- Console.WriteLine($"Star power collected: {energy}");
- PrintMatrix(matrix);
- }
- private static void PrintMatrix(char[][] matrix)
- {
- foreach (var row in matrix)
- {
- Console.WriteLine($"{string.Join("", row)}");
- }
- return;
- }
- public static bool IsInMatrix(char[][] matrix, int row, int col)
- {
- if (row >= 0 && row < matrix.Length && col >= 0 && col < matrix[row].Length)
- {
- return true;
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement