Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _01.ForExamPrep
- {
- class LabyrinthDash
- {
- static void Main(string[] args)
- {
- int lives = 3;
- int numberOfRows = int.Parse(Console.ReadLine());
- char[][] board = new char[numberOfRows][];
- for (int i = 0; i < numberOfRows; i++)
- {
- string inputLine = Console.ReadLine();
- board[i] = inputLine.ToCharArray();
- }
- int row = 0;
- int col = 0;
- int movesMade = 0;
- string commands = Console.ReadLine();
- foreach (var directions in commands)
- {
- if (lives <= 0)
- {
- Console.WriteLine("No lives left! Game Over!");
- break;
- }
- int previousrow = row;
- int previoucol = col;
- switch (directions)
- {
- case '<' :
- col--;
- break;
- case '>':
- col++;
- break;
- case'v':
- row++;
- break;
- case'^':
- row--;
- break;
- }
- if (!isCellInsideMatrix(row,col,board) || board[row][col] == ' ')
- {
- Console.WriteLine("Fell off a cliff! Game Over!");
- movesMade++;
- break;
- }
- else if (board[row][col] == '.')
- {
- Console.WriteLine("Made a move!");
- movesMade++;
- }
- else if (board[row][col] == '_' || board[row][col] == '|')
- {
- Console.WriteLine("Bumped a wall.");
- row = previousrow;
- col = previoucol;
- }
- else if (board[row][col] == '$')
- {
- lives++;
- Console.WriteLine("Awesome! Lives left: {0}", lives);
- movesMade++;
- board[row][col] = '.';
- }
- else if (board[row][col] == '@' || board[row][col] == '#' || board[row][col] == '*')
- {
- movesMade++;
- lives--;
- Console.WriteLine("Ouch! That hurt! Lives left: {0}", lives);
- }
- char currentCell = board[row][col];
- }
- Console.WriteLine("Total moves made: {0}",movesMade);
- }
- private static bool isCellInsideMatrix(int row, int col, char[][] board)
- {
- bool isRowInsideMatrix = 0 <= row && row < board.Length;
- if (!isRowInsideMatrix)
- {
- return false;
- }
- return col >= 0 && col < board[row].Length;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement