Advertisement
Guest User

LabyrinthDash

a guest
May 25th, 2015
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _01.ForExamPrep
  8. {
  9. class LabyrinthDash
  10. {
  11.  
  12.  
  13.  
  14. static void Main(string[] args)
  15. {
  16. int lives = 3;
  17. int numberOfRows = int.Parse(Console.ReadLine());
  18. char[][] board = new char[numberOfRows][];
  19. for (int i = 0; i < numberOfRows; i++)
  20. {
  21. string inputLine = Console.ReadLine();
  22. board[i] = inputLine.ToCharArray();
  23.  
  24. }
  25. int row = 0;
  26. int col = 0;
  27. int movesMade = 0;
  28. string commands = Console.ReadLine();
  29. foreach (var directions in commands)
  30. {
  31. if (lives <= 0)
  32. {
  33. Console.WriteLine("No lives left! Game Over!");
  34. break;
  35. }
  36. int previousrow = row;
  37. int previoucol = col;
  38.  
  39. switch (directions)
  40. {
  41.  
  42. case '<' :
  43. col--;
  44. break;
  45. case '>':
  46. col++;
  47. break;
  48. case'v':
  49. row++;
  50. break;
  51. case'^':
  52. row--;
  53. break;
  54.  
  55. }
  56.  
  57. if (!isCellInsideMatrix(row,col,board) || board[row][col] == ' ')
  58. {
  59. Console.WriteLine("Fell off a cliff! Game Over!");
  60. movesMade++;
  61. break;
  62. }
  63. else if (board[row][col] == '.')
  64. {
  65. Console.WriteLine("Made a move!");
  66. movesMade++;
  67.  
  68. }
  69. else if (board[row][col] == '_' || board[row][col] == '|')
  70. {
  71. Console.WriteLine("Bumped a wall.");
  72. row = previousrow;
  73. col = previoucol;
  74.  
  75.  
  76. }
  77.  
  78. else if (board[row][col] == '$')
  79. {
  80. lives++;
  81. Console.WriteLine("Awesome! Lives left: {0}", lives);
  82. movesMade++;
  83.  
  84. board[row][col] = '.';
  85. }
  86. else if (board[row][col] == '@' || board[row][col] == '#' || board[row][col] == '*')
  87. {
  88. movesMade++;
  89. lives--;
  90. Console.WriteLine("Ouch! That hurt! Lives left: {0}", lives);
  91.  
  92.  
  93. }
  94. char currentCell = board[row][col];
  95.  
  96.  
  97.  
  98.  
  99. }
  100. Console.WriteLine("Total moves made: {0}",movesMade);
  101.  
  102. }
  103. private static bool isCellInsideMatrix(int row, int col, char[][] board)
  104. {
  105. bool isRowInsideMatrix = 0 <= row && row < board.Length;
  106. if (!isRowInsideMatrix)
  107. {
  108. return false;
  109.  
  110. }
  111. return col >= 0 && col < board[row].Length;
  112.  
  113. }
  114. }
  115.  
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement