Advertisement
Guest User

Untitled

a guest
Jul 9th, 2021
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Man_O_War
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] pirateShip = Console.ReadLine().Split(">").Select(int.Parse).ToArray();
  11. int[] warShip = Console.ReadLine().Split(">").Select(int.Parse).ToArray();
  12. int maxHealthSection = int.Parse(Console.ReadLine());
  13.  
  14. string[] command = Console.ReadLine().Split();
  15.  
  16. while (command[0] != "Retire")
  17. {
  18. if (command[0] == "Fire")
  19. {
  20. if (int.Parse(command[1]) >=0 && int.Parse(command[1]) < warShip.Length)
  21. {
  22. int index = int.Parse(command[1]);
  23. int demage = int.Parse(command[2]);
  24.  
  25. warShip[index] -= demage;
  26. if (warShip[index] <= 0)
  27. {
  28. Console.WriteLine("You won! The enemy ship has sunken.");
  29. return;
  30. }
  31. }
  32. }
  33. else if (command[0] == "Defend")
  34. {
  35. int startIndex = int.Parse(command[1]);
  36. int endIndex = int.Parse(command[2]);
  37. int demage = int.Parse(command[3]);
  38.  
  39. if (startIndex >= 0 && endIndex < pirateShip.Length)
  40. {
  41. for (int i = startIndex; i <= endIndex; i++)
  42. {
  43. pirateShip[i] -= demage;
  44. if (pirateShip[i] <=0)
  45. {
  46. Console.WriteLine($"You lost! The pirate ship has sunken.");
  47. return;
  48. }
  49. }
  50. }
  51. }
  52. else if (command[0] == "Repair")
  53. {
  54. if (int.Parse(command[1]) >= 0 && int.Parse(command[1]) < warShip.Length)
  55. {
  56. int index = int.Parse(command[1]);
  57. int addHealthSection = int.Parse(command[2]);
  58.  
  59. if (pirateShip[index] + addHealthSection > maxHealthSection)
  60. {
  61. pirateShip[index] = maxHealthSection;
  62. }
  63. else
  64. {
  65. pirateShip[index] += addHealthSection;
  66. }
  67. }
  68. }
  69. else if (command[0] == "Status")
  70. {
  71. int counter = 0;
  72. double attentionHealth = maxHealthSection * 0.2;
  73.  
  74. for (int i = 0; i < pirateShip.Length; i++)
  75. {
  76. if (pirateShip[i] < attentionHealth)
  77. {
  78. counter++;
  79. }
  80. }
  81. Console.WriteLine($"{counter} sections need repair.");
  82. }
  83.  
  84. command = Console.ReadLine().Split();
  85. }
  86.  
  87. Console.WriteLine($"Pirate ship status: {pirateShip.Sum()}{Environment.NewLine}Warship status: {warShip.Sum()}");
  88.  
  89. }
  90. }
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement