Guest User

Untitled

a guest
Apr 30th, 2020
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 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> warShip = Console.ReadLine().Split(">").Select(int.Parse).ToList();
  13. int maxHealth = int.Parse(Console.ReadLine());
  14.  
  15. string command;
  16. while ((command = Console.ReadLine()) != "Retire")
  17. {
  18. string[] a = command.Split(' ').ToArray();
  19. if (a[0] == "Fire")
  20. {
  21. int index = int.Parse(a[1]);
  22.  
  23. int fire = int.Parse(a[2]);
  24. if (index >= 0 && index < warShip.Count)
  25. {
  26.  
  27. warShip[index] -= fire;
  28.  
  29. if (warShip[index] <= 0)
  30. {
  31. Console.WriteLine("You won! The enemy ship has sunken.");
  32. return;
  33. }
  34. }
  35. }
  36. if (a[0] == "Defend")
  37. {
  38. int startIndex = int.Parse(a[1]);
  39. int endIndex = int.Parse(a[2]);
  40. int dmg = int.Parse(a[3]);
  41. if (startIndex >= 0 && startIndex < pirateShip.Count && endIndex >= 0 && endIndex < pirateShip.Count && dmg >= 0)
  42. {
  43. for (int i = startIndex; i <= endIndex; i++)
  44. {
  45. int n = i;
  46. pirateShip[n] -= dmg;
  47.  
  48. if (pirateShip[i] <= 0)
  49. {
  50. Console.WriteLine("You lost! The pirate ship has sunken.");
  51. return;
  52. }
  53. }
  54. }
  55. }
  56. if (a[0] == "Repair")
  57. {
  58. int healIndex = int.Parse(a[1]);
  59. int heal = int.Parse(a[2]);
  60. if (healIndex >= 0 && healIndex < pirateShip.Count && heal >= 0)
  61. {
  62.  
  63. pirateShip[healIndex] += heal;
  64.  
  65. if (pirateShip[healIndex] > maxHealth)
  66. {
  67. pirateShip[healIndex] = maxHealth;
  68. }
  69.  
  70. }
  71.  
  72. }
  73. if (a[0] == "Status")
  74. {
  75. int broken = 0;
  76. double lowH = maxHealth - (maxHealth * 0.8);
  77. for (int i = 0; i < pirateShip.Count; i++)
  78. {
  79. if (lowH > pirateShip[i])
  80. {
  81. broken++;
  82. }
  83.  
  84. }
  85. Console.WriteLine($"{broken} sections need repair.");
  86.  
  87. }
  88. }
  89. int pirateResult = 0;
  90. int warResult = 0;
  91.  
  92. for (int i = 0; i < pirateShip.Count; i++)
  93. {
  94. pirateResult += pirateShip[i];
  95. }
  96.  
  97. Console.WriteLine($"Pirate ship status: {pirateResult}");
  98. for (int i = 0; i < warShip.Count; i++)
  99. {
  100. warResult += warShip[i];
  101.  
  102. }
  103.  
  104. Console.WriteLine($"Warship status: {warResult}");
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment