Guest User

04.TrifonQuest

a guest
Jun 12th, 2016
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. namespace _04.TrifoQuest
  2. {
  3. using System;
  4. using System.Linq;
  5.  
  6. public class TrifoMain
  7. {
  8. public static void Main(string[] args)
  9. {
  10. long health = int.Parse(Console.ReadLine());
  11.  
  12. char[,] grid = InitializeGrid();
  13.  
  14. int turnsCount = 0;
  15.  
  16. for (int col = 0; col < grid.GetLength(1); col++)
  17. {
  18. if (col % 2 == 0)
  19. {
  20. for (int row = 0; row < grid.GetLength(0); row++)
  21. {
  22. ApplyPosition(grid, row, col, ref health, ref turnsCount);
  23. }
  24. }
  25. else
  26. {
  27. for (int row = grid.GetLength(0) - 1; row >= 0; row--)
  28. {
  29. ApplyPosition(grid, row, col, ref health, ref turnsCount);
  30. }
  31. }
  32. }
  33.  
  34. Console.WriteLine($"Quest completed!\nHealth: {health}\nTurns: {turnsCount}");
  35. }
  36.  
  37. private static void ApplyPosition(char[,] grid, int row, int col, ref long health, ref int turnsCount)
  38. {
  39. switch (grid[row, col])
  40. {
  41. case 'F':
  42. health -= (turnsCount / 2);
  43. if (health <= 0)
  44. {
  45. Console.WriteLine($"Died at: [{row}, {col}]");
  46. Environment.Exit(0);
  47. }
  48.  
  49. break;
  50. case 'H':
  51. health += (turnsCount / 3);
  52. break;
  53. case 'T':
  54. turnsCount+= 2;
  55. break;
  56. }
  57.  
  58. turnsCount++;
  59. }
  60.  
  61. private static char[,] InitializeGrid()
  62. {
  63. int[] gridInfo = Console.ReadLine()
  64. .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
  65. .Select(int.Parse)
  66. .ToArray();
  67.  
  68. char[,] grid = new char[gridInfo[0], gridInfo[1]];
  69.  
  70. for (int row = 0; row < gridInfo[0]; row++)
  71. {
  72. char[] currentrow = Console.ReadLine().ToCharArray();
  73.  
  74. for (int col = 0; col < gridInfo[1]; col++)
  75. {
  76. grid[row, col] = currentrow[col];
  77. }
  78. }
  79.  
  80. return grid;
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment