Guest User

Man O War

a guest
Apr 30th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Treasure_Hunt
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> pirateShip = Console.ReadLine().Split(">").Select(int.Parse).ToList();
  12. List<int> low = new List<int>(pirateShip);
  13. int counter = 0;
  14. int counter1 = 0;
  15. List<int> warShip = Console.ReadLine().Split(">").Select(int.Parse).ToList();
  16. int health = int.Parse(Console.ReadLine());
  17. int broken = 0;
  18. string command;
  19. while ((command = Console.ReadLine()) != "Retire")
  20. {
  21. string[] a = command.Split(' ').ToArray();
  22. if (a[0] == "Fire")
  23. {
  24. int indeex = int.Parse(a[1]);
  25.  
  26. int fire = int.Parse(a[2]);
  27. if (indeex >= 0 && indeex < warShip.Count)
  28. {
  29. int d = warShip[indeex];
  30. int damage = d - fire;
  31.  
  32. warShip.RemoveAt(indeex);
  33. warShip.Insert(indeex, damage);
  34. if (damage <= 0)
  35. {
  36. Console.WriteLine("You won! The enemy ship has sunken.");
  37. break;
  38. }
  39. }
  40. }
  41. if (a[0] == "Defend")
  42. {
  43. int startIndex = int.Parse(a[1]);
  44. int endIndex = int.Parse(a[2]);
  45. int dmg = int.Parse(a[3]);
  46. if (startIndex >= 0 && startIndex < pirateShip.Count && endIndex >= 0 && endIndex < pirateShip.Count && dmg >= 0)
  47. {
  48. for (int i = startIndex; i <= endIndex; i++)
  49. {
  50. int n = i;
  51. pirateShip[n] -= dmg;
  52.  
  53. if (dmg >= pirateShip[i])
  54. {
  55.  
  56. counter++;
  57.  
  58. break;
  59. }
  60. }
  61. if (counter > 0)
  62. {
  63. Console.WriteLine("You lost! The pirate ship has sunken.");
  64. break;
  65. }
  66. }
  67.  
  68. {
  69.  
  70. }
  71. }
  72. if (a[0] == "Repair")
  73. {
  74. int healIndex = int.Parse(a[1]);
  75. int heal = int.Parse(a[2]);
  76. if (healIndex >= 0 && healIndex < pirateShip.Count && heal >= 0)
  77. {
  78. int currentBox = pirateShip[healIndex];
  79. if (currentBox <= health)
  80. {
  81. int potion = currentBox + heal;
  82. if (potion > health)
  83. {
  84. potion = health;
  85. }
  86. pirateShip.RemoveAt(healIndex);
  87.  
  88. pirateShip.Insert(healIndex, potion);
  89. }
  90. }
  91. }
  92. if (a[0] == "Status")
  93. {
  94.  
  95. double lowH = health - (health * 0.8);
  96. for (int i = 0; i < pirateShip.Count; i++)
  97. {
  98.  
  99.  
  100. if (lowH > pirateShip[i])
  101. {
  102. broken++;
  103.  
  104. }
  105. }
  106. Console.WriteLine($"{broken} sections need repair.");
  107. }
  108. }
  109. int pirateResult = 0;
  110. int warResult = 0;
  111. if (counter == 0)
  112. {
  113. for (int i = 0; i < pirateShip.Count; i++)
  114. {
  115. pirateResult += pirateShip[i];
  116.  
  117. }
  118. Console.WriteLine($"Pirate ship status: {pirateResult}");
  119. for (int i = 0; i < warShip.Count; i++)
  120. {
  121. warResult += warShip[i];
  122.  
  123. }
  124. Console.WriteLine($"Warship status: {warResult}");
  125. }
  126.  
  127.  
  128. }
  129.  
  130. }
  131. }
Add Comment
Please, Sign In to add comment