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