Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ManOWar
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> pirateShipStatus = Console.ReadLine().Split(">").Select(int.Parse).ToList();
- List<int> warshipStatus = Console.ReadLine().Split(">").Select(int.Parse).ToList();
- int maximumHealth = int.Parse(Console.ReadLine());
- string command = null;
- while ((command = Console.ReadLine()) != "Retire")
- {
- string[] commands = command.Split();
- if (commands[0] == "Fire")
- {
- int index = int.Parse(commands[1]);
- int damage = int.Parse(commands[2]);
- if (index >= 0 && index < warshipStatus.Count)
- {
- warshipStatus[index] -= damage;
- if (warshipStatus[index] <= 0)
- {
- Console.WriteLine($"You won! The enemy ship has sunken.");
- return;
- }
- else
- {
- continue;
- }
- }
- }
- else if (commands[0] == "Defend")
- {
- int startIndex = int.Parse(commands[1]);
- int endIndex = int.Parse(commands[2]);
- int damage = int.Parse(commands[3]);
- if (startIndex >= 0 && startIndex < pirateShipStatus.Count && endIndex >= 0 && endIndex < pirateShipStatus.Count)
- {
- for (int i = startIndex; i <= endIndex; i++)
- {
- pirateShipStatus[i] -= damage;
- if (pirateShipStatus[i] <= 0)
- {
- Console.WriteLine($"You lost! The pirate ship has sunken.");
- return;
- }
- }
- }
- else
- {
- continue;
- }
- }
- else if (commands[0] == "Repair")
- {
- int index = int.Parse(commands[1]);
- int health = int.Parse(commands[2]);
- if (index >= 0 && index < pirateShipStatus.Count)
- {
- if (pirateShipStatus[index] + health <= maximumHealth)
- {
- pirateShipStatus[index] += health;
- }
- else
- {
- pirateShipStatus[index] = maximumHealth;
- }
- }
- }
- else if (commands[0] == "Status")
- {
- double neededRepair = 0.20 * maximumHealth;
- int counter = 0;
- foreach (var sections in pirateShipStatus)
- {
- if (sections < neededRepair)
- {
- counter++;
- }
- }
- Console.WriteLine($"{counter} sections need repair.");
- }
- }
- Console.WriteLine($"Pirate ship status: {pirateShipStatus.Sum()}");
- Console.WriteLine($"Warship status: {warshipStatus.Sum()}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement