Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class LabyrinthDash
- {
- public static void Main()
- {
- const string ObstacleCharacters = "*#@";
- int numberOfRows = int.Parse(Console.ReadLine());
- char[][] matrix = new char[numberOfRows][];
- for (int i = 0; i < numberOfRows; i++)
- {
- string inputLine = Console.ReadLine();
- matrix[i] = inputLine.ToCharArray();
- }
- string commads = Console.ReadLine();
- int livesLeft = 3;
- int row = 0;
- int col = 0;
- int movesMade = 0;
- foreach (var direction in commads)
- {
- int previousRow = row;
- int previousCol = col;
- switch (direction)
- {
- case '<':
- col--;
- break;
- case '>':
- col++;
- break;
- case 'v':
- row++;
- break;
- case '^':
- row--;
- break;
- }
- if (!IsCellIsideMatrix(row, col, matrix) || matrix[row][col] == ' ')
- {
- Console.WriteLine("Fell off a cliff! Game Over!");
- movesMade++;
- break;
- }
- if (matrix[row][col] == '_' || matrix[row][col] == '|')
- {
- Console.WriteLine("Bumped a wall.");
- row = previousRow;
- col = previousCol;
- }
- else if (ObstacleCharacters.Contains(matrix[row][col].ToString()))
- {
- livesLeft--;
- movesMade++;
- Console.WriteLine("Ouch! That hurt! Lives left: {0}", livesLeft);
- if (livesLeft <= 0)
- {
- Console.WriteLine("No lives left! Game Over!");
- break;
- }
- }
- else if (matrix[row][col] == '$')
- {
- livesLeft++;
- movesMade++;
- matrix[row][col] = '.';
- Console.WriteLine("Awesome! Lives left: {0}", livesLeft);
- }
- else
- {
- movesMade++;
- Console.WriteLine("Made a move!");
- }
- }
- Console.WriteLine("Total moves made: {0}", movesMade);
- }
- private static bool IsCellIsideMatrix(int row, int col, char[][] matrix)
- {
- bool isRowInsideMatrix = 0 <= row && row < matrix.Length;
- if (!isRowInsideMatrix)
- {
- return false;
- }
- bool isColInRange = 0 <= col && col < matrix[row].Length;
- return isColInRange;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement