Advertisement
osman1997

supermario

Apr 14th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. using System;
  2.  
  3. namespace matrixretakeexamadvanced
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int marioLive = int.Parse(Console.ReadLine());
  10. int n = int.Parse(Console.ReadLine());
  11.  
  12. char[,] matrix = new char[n, n];
  13.  
  14. int marioOldRow = 0;
  15. int marioOldCol = 0;
  16.  
  17. int marioNewRow = 0;
  18. int marioNewCol = 0;
  19.  
  20. bool isWon = false;
  21.  
  22.  
  23. for (int rows = 0; rows < n; rows++)
  24. {
  25. var command = Console.ReadLine().ToCharArray();
  26.  
  27. for (int cols = 0; cols < n; cols++)
  28. {
  29. matrix[rows, cols] = command[cols];
  30.  
  31. if(matrix[rows, cols] == 'M')
  32. {
  33. marioNewRow = rows;
  34. marioNewCol = cols;
  35. }
  36. }
  37. }
  38.  
  39.  
  40. //down=(row++, col), up=(row--, col), right=(row, col++), left=(row, col--)
  41.  
  42. matrix[marioNewRow, marioNewCol] = '-';
  43.  
  44.  
  45. while (true)
  46. {
  47. string[] command = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
  48.  
  49. marioOldRow = marioNewRow;
  50. marioOldCol = marioNewCol;
  51.  
  52. string direction = command[0];
  53. int bowserRow = int.Parse(command[1]);
  54. int bowserCol = int.Parse(command[2]);
  55.  
  56. matrix[bowserRow, bowserCol] = 'B';
  57.  
  58. matrix[marioOldRow, marioOldCol] = '-';
  59.  
  60. if(direction == "W")
  61. {
  62. if(IsValidCell(marioNewRow -= 1, marioNewCol, n))
  63. {
  64. }
  65.  
  66. }
  67. else if(direction == "S")
  68. {
  69. if (IsValidCell(marioNewRow += 1, marioNewCol, n))
  70. {
  71. }
  72. }
  73. else if(direction == "A")
  74. {
  75. if (IsValidCell(marioNewRow, marioNewCol -= 1, n))
  76. {
  77. }
  78. }
  79. else if(direction == "D")
  80. {
  81. if (IsValidCell(marioNewRow, marioNewCol += 1, n))
  82. {
  83. }
  84. }
  85. marioLive -= 1;
  86.  
  87. if(matrix[marioNewRow, marioNewCol] == 'B')
  88. {
  89. marioLive -= 2;
  90. }
  91. if (matrix[marioNewRow, marioNewCol] == 'P')
  92. {
  93. matrix[marioNewRow, marioNewCol] = '-';
  94. isWon = true;
  95. break;
  96. }
  97.  
  98. if (marioLive <= 0)
  99. {
  100. matrix[marioNewRow, marioNewCol] = 'X';
  101. break;
  102. }
  103.  
  104. matrix[marioNewRow, marioNewCol] = 'M';
  105. }
  106.  
  107.  
  108. if (isWon)
  109. {
  110. Console.WriteLine($"Mario has successfully saved the princess! Lives left: {marioLive}");
  111. }
  112. else
  113. {
  114. Console.WriteLine($"Mario died at {marioNewRow};{marioNewCol}.");
  115. }
  116.  
  117. for (int rows = 0; rows < n; rows++)
  118. {
  119. for (int cols = 0; cols < n; cols++)
  120. {
  121. Console.Write(matrix[rows, cols]);
  122. }
  123. Console.WriteLine();
  124. }
  125. }
  126.  
  127. private static bool IsValidCell(int row, int col, int n)
  128. {
  129. return row >= 0 && row < n && col >= 0 && col < n;
  130.  
  131. }
  132. }
  133. }
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement