Advertisement
Guest User

Untitled

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