Advertisement
nedka_sotirova

ReVolt

Feb 25th, 2020
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ReVolt
  4. {
  5.  
  6. class Program
  7. {
  8. static int N;
  9. static char[][] matrix;
  10. static int currentRow;
  11. static int currentCol;
  12. static void Main(string[] args)
  13. {
  14. N = int.Parse(Console.ReadLine());
  15. matrix = new char[N][];
  16. int countOfCommands = int.Parse(Console.ReadLine());
  17. for (int i = 0; i < N; i++)
  18. {
  19. var line = Console.ReadLine();
  20. matrix[i] = line.ToCharArray();
  21. }
  22. for (int row = 0; row < N; row++)
  23. {
  24. for (int col = 0; col < matrix[row].Length; col++)
  25. {
  26. if (matrix[row][col] == 'f')
  27. {
  28. currentRow = row;
  29. currentCol = col;
  30. }
  31. }
  32. }
  33. bool playerWon = false;
  34. for (int i = 0; i < countOfCommands; i++)
  35. {
  36. var command = Console.ReadLine();
  37. matrix[currentRow][currentCol] = '-';
  38. Move(command);
  39. switch (matrix[currentRow][currentCol])
  40. {
  41. case 'B': Move(command);
  42. if (matrix[currentRow][currentCol] == 'F')
  43. {
  44. playerWon = true;
  45. matrix[currentRow][currentCol] = 'f';
  46. }
  47. break;
  48. case 'T': Move(BackDirection(command));
  49. break;
  50. case 'F':
  51. playerWon = true;
  52. matrix[currentRow][currentCol] = 'f';
  53. break;
  54. }
  55. if (playerWon)
  56. {
  57. break;
  58. }
  59. matrix[currentRow][currentCol] = 'f';
  60. }
  61. if (playerWon) Console.WriteLine("Player won!");
  62. else Console.WriteLine("Player lost!");
  63.  
  64. foreach (var row in matrix)
  65. {
  66. Console.WriteLine(string.Join("",row));
  67. }
  68. }
  69. static void Move(string command)
  70. {
  71. switch(command)
  72. {
  73.  
  74. case "up": currentRow--;
  75. if (currentRow<0)
  76. {
  77. currentRow = N - 1;
  78. }
  79. break;
  80. case "down": currentRow++;
  81. if (currentRow==N)
  82. {
  83. currentRow = 0;
  84. }
  85. break;
  86. case "left": currentCol--;
  87. if (currentCol<0)
  88. {
  89. currentCol = N-1;
  90. }
  91. break;
  92. case "right": currentCol++;
  93. if (currentCol==N)
  94. {
  95. currentCol = 0;
  96. }
  97. break;
  98. }
  99.  
  100. }
  101. static string BackDirection(string direction)
  102. {
  103. switch (direction)
  104. {
  105. case "up": return "down";
  106. case "down": return "up";
  107. case "left": return "right";
  108. case "right": return "left";
  109. default: return null;
  110. }
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement