Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _02.Space
- {
- class Program
- {
- static void Main(string[] args)
- {
- int size = int.Parse(Console.ReadLine());
- char[][] matrix = new char[size][];
- int currentRow = 0;
- int currentCol = 0;
- bool spaceshipPosFound = false;
- for (int row = 0; row < size; row++)
- {
- char[] currentRowElements = Console.ReadLine().ToCharArray();
- if (!spaceshipPosFound)
- {
- for (int col = 0; col < size; col++)
- {
- if (currentRowElements[col] == 'S')
- {
- currentRow = row;
- currentCol = col;
- spaceshipPosFound = true;
- break;
- }
- }
- }
- matrix[row] = currentRowElements;
- }
- int stars = 0;
- while (stars < 50)
- {
- string command = Console.ReadLine();
- matrix[currentRow][currentCol] = '-';
- if (command == "up")
- {
- currentRow--;
- }
- else if (command == "down")
- {
- currentRow++;
- }
- else if (command == "left")
- {
- currentCol--;
- }
- else if (command == "right")
- {
- currentCol++;
- }
- if (!ValidateIndex(currentRow, currentCol, size))
- {
- break;
- }
- char symbol = matrix[currentRow][currentCol];
- if (symbol == 'O')
- {
- matrix[currentRow][currentCol] = '-';
- for (int row = 0; row < size; row++)
- {
- bool isFound = false;
- for (int col = 0; col < size; col++)
- {
- char currentSymbol = matrix[row][col];
- if (currentSymbol == 'O')
- {
- currentRow = row; //?
- currentCol = col;
- isFound = true;
- break;
- }
- }
- if (isFound)
- {
- break;
- }
- }
- }
- if (char.IsDigit(symbol))
- {
- stars += int.Parse(symbol.ToString());
- }
- matrix[currentRow][currentCol] = 'S';
- }
- if(stars < 50)
- {
- Console.WriteLine("Bad news, the spaceship went to the void.");
- }
- else
- {
- Console.WriteLine("Good news! Stephen succeeded in collecting enough star power!");
- }
- Console.WriteLine($"Star power collected: {stars}");
- for (int row = 0; row < size; row++)
- {
- for (int col = 0; col < size; col++)
- {
- Console.Write(matrix[row][col]);
- }
- Console.WriteLine();
- }
- }
- public static bool ValidateIndex(int row, int col, int size)
- {
- return row >= 0 && row < size && col >= 0 && col < size;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment