Advertisement
AnastasiyaG

Untitled

Feb 28th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Man_O_War
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> PirateShip = Console.ReadLine()
  12. .Split('>')
  13. .Select(int.Parse)
  14. .ToList();
  15. List<int> WarShip = Console.ReadLine()
  16. .Split('>')
  17. .Select(int.Parse)
  18. .ToList();
  19. double maxHelth = double.Parse(Console.ReadLine());
  20. bool PrintFullStatus = true;
  21.  
  22. while (true)
  23. {
  24. string[] commands = Console.ReadLine()
  25. .Split()
  26. .ToArray();
  27. if (commands[0] == "Retire")
  28. { break; }
  29.  
  30. if (commands[0] == "Fire")
  31. { int index = int.Parse(commands[1]);
  32. int damage = int.Parse(commands[2]);
  33. if (index >= 0 && index <= WarShip.Count - 1)
  34. {
  35. WarShip[index] -= damage;
  36. if (WarShip[index] <= 0)
  37. { Console.WriteLine("You won!The enemy ship has sunken.");
  38. PrintFullStatus = false;
  39. break;
  40. }
  41.  
  42. }
  43. else
  44. { continue; }
  45. }
  46. if (commands[0] == "Defend")
  47. {
  48. int startIndex = int.Parse(commands[1]);
  49. int endIndex = int.Parse(commands[2]);
  50. int damage = int.Parse(commands[3]);
  51. if (startIndex >= 0 && startIndex <= PirateShip.Count - 1 && endIndex >= 0 && endIndex <= PirateShip.Count - 1)
  52. { GetDefendShip(PirateShip, startIndex, endIndex, damage);
  53. for (int i = 0; i < PirateShip.Count; i++)
  54. {if (PirateShip[i] <= 0)
  55. { Console.WriteLine("You lost! The pirate ship has sunken.");
  56. PrintFullStatus = false;
  57. break;
  58. }
  59.  
  60. }
  61. }
  62. else
  63. { continue; }
  64.  
  65. }
  66. if (commands[0] == "Repair")
  67. { int indexRepair = int.Parse(commands[1]);
  68. int helth = int.Parse(commands[2]);
  69. if (indexRepair >= 0 && indexRepair <= PirateShip.Count - 1)
  70. {
  71. PirateShip[indexRepair] += helth;
  72. if (PirateShip[indexRepair] > maxHelth)
  73. { PirateShip[indexRepair] = int.Parse($"{maxHelth}");
  74. }
  75. }
  76. else { continue; }
  77. }
  78. if (commands[0] == "Status")
  79. {
  80. double twentyPercnt = (maxHelth * 0.20);
  81. int counter = 0;
  82. for (int i = 0; i <PirateShip.Count-1; i++)
  83. { if (PirateShip[i] < twentyPercnt)
  84. { counter++; }
  85.  
  86. }
  87. if (counter > 0)
  88. { Console.WriteLine($"{counter} sections need repair."); }
  89. }
  90. }
  91. if (PrintFullStatus)
  92. {
  93. int sumPirat = PirateShip.Sum();
  94. int WarShipsum = WarShip.Sum();
  95.  
  96. Console.WriteLine($"Pirate ship status: {sumPirat}");
  97. Console.WriteLine($"Warship status: {WarShipsum}");
  98.  
  99. }
  100.  
  101. }
  102.  
  103. static List<int> GetDefendShip(List<int> pirateShip, int startIndex, int endIndex, int damage)
  104. {if (startIndex <= endIndex)
  105. {
  106. for (int i = startIndex; i <= endIndex; i++)
  107. {
  108. pirateShip[i] -= damage;
  109.  
  110. }
  111. }
  112.  
  113. return pirateShip;
  114. }
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement