MeGaDeTH_91

10.

Feb 1st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _10._The_Heigan_Dance
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. double damage = double.Parse(Console.ReadLine());
  12.  
  13. double heiganHealth = 3000000;
  14. int playerHealth = 18500;
  15.  
  16. int rowPosition = 7;
  17. int colPosition = 7;
  18.  
  19. Queue<int> cloudQueue = new Queue<int>();
  20.  
  21. string lastSpell = string.Empty;
  22.  
  23. while (heiganHealth > 0 && playerHealth > 0)
  24. {
  25. string[] inputLine = Console.ReadLine()
  26. .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  27. .ToArray();
  28.  
  29. string currSpell = inputLine[0];
  30. int impactRow = int.Parse(inputLine[1]);
  31. int impactCol = int.Parse(inputLine[2]);
  32.  
  33. heiganHealth -= damage;
  34.  
  35. if(cloudQueue.Count > 0)
  36. {
  37. playerHealth -= cloudQueue.Dequeue();
  38. if(playerHealth <= 0 || heiganHealth <= 0)
  39. {
  40. continue;
  41. }
  42. }
  43.  
  44. if (heiganHealth <= 0)
  45. {
  46. continue;
  47. }
  48.  
  49. if (IsCellReached(rowPosition, colPosition, impactRow, impactCol) &&
  50. IsPlayerDamaged(ref rowPosition, ref colPosition, impactRow, impactCol))
  51. {
  52. if (currSpell == "Cloud")
  53. {
  54. lastSpell = "Plague Cloud";
  55. playerHealth -= 3500;
  56. cloudQueue.Enqueue(3500);
  57. }
  58. else if (currSpell == "Eruption")
  59. {
  60. lastSpell = "Eruption";
  61. playerHealth -= 6000;
  62. }
  63. }
  64.  
  65. }
  66.  
  67. string heiganPrint = heiganHealth <= 0 ? $"Heigan: Defeated!" : $"Heigan: {heiganHealth:F2}";
  68.  
  69. string playerPrint = playerHealth <= 0 ? $"Player: Killed by {lastSpell}" : $"Player: {playerHealth}";
  70.  
  71. string positionPrint = $"Final position: {rowPosition}, {colPosition}";
  72.  
  73. Console.WriteLine(heiganPrint);
  74. Console.WriteLine(playerPrint);
  75. Console.WriteLine(positionPrint);
  76. }
  77.  
  78. private static bool IsPlayerDamaged(ref int rowPos, ref int colPos, int hitRow, int hitCol)
  79. {
  80. if (rowPos > 0 &&
  81. !IsCellReached(rowPos - 1, colPos, hitRow, hitCol)) // Try move Up
  82. {
  83. rowPos--;
  84. return false;
  85. }
  86.  
  87. if (colPos + 1 < 15 && // Dancing area is 15 by 15 matrix
  88. !IsCellReached(rowPos, colPos + 1, hitRow, hitCol)) // Try move Right
  89. {
  90. colPos++;
  91. return false;
  92. }
  93.  
  94. if (rowPos + 1 < 15 && // Dancing area is 15 by 15 matrix
  95. !IsCellReached(rowPos + 1, colPos, hitRow, hitCol)) // Try move Down
  96. {
  97. rowPos++;
  98. return false;
  99. }
  100.  
  101. if (colPos > 0 &&
  102. !IsCellReached(rowPos, colPos - 1, hitRow, hitCol)) // Try move Left
  103. {
  104. colPos--;
  105. return false;
  106. }
  107.  
  108. return true;
  109. }
  110.  
  111. private static bool IsCellReached(int cellRow, int cellCol, int hitRow, int hitCol)
  112. {
  113. return (cellRow >= hitRow - 1) && (cellRow <= hitRow + 1) && (cellCol >= hitCol - 1) && (cellCol <= hitCol + 1);
  114. }
  115. }
  116. }
Add Comment
Please, Sign In to add comment