Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Man_O_War
- {
- 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();
- double maxHelth = double.Parse(Console.ReadLine());
- bool PrintFullStatus = true;
- while (true)
- {
- string[] commands = Console.ReadLine()
- .Split()
- .ToArray();
- if (commands[0] == "Retire")
- { break; }
- if (commands[0] == "Fire")
- { int index = int.Parse(commands[1]);
- int damage = int.Parse(commands[2]);
- if (index >= 0 && index <= WarShip.Count - 1)
- {
- WarShip[index] -= damage;
- if (WarShip[index] <= 0)
- { Console.WriteLine("You won!The enemy ship has sunken.");
- PrintFullStatus = false;
- break;
- }
- }
- else
- { continue; }
- }
- 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 <= PirateShip.Count - 1 && endIndex >= 0 && endIndex <= PirateShip.Count - 1)
- { GetDefendShip(PirateShip, startIndex, endIndex, damage);
- for (int i = 0; i < PirateShip.Count; i++)
- {if (PirateShip[i] <= 0)
- { Console.WriteLine("You lost! The pirate ship has sunken.");
- PrintFullStatus = false;
- break;
- }
- }
- }
- else
- { continue; }
- }
- if (commands[0] == "Repair")
- { int indexRepair = int.Parse(commands[1]);
- int helth = int.Parse(commands[2]);
- if (indexRepair >= 0 && indexRepair <= PirateShip.Count - 1)
- {
- PirateShip[indexRepair] += helth;
- if (PirateShip[indexRepair] > maxHelth)
- { PirateShip[indexRepair] = int.Parse($"{maxHelth}");
- }
- }
- else { continue; }
- }
- if (commands[0] == "Status")
- {
- double twentyPercnt = (maxHelth * 0.20);
- int counter = 0;
- for (int i = 0; i <PirateShip.Count-1; i++)
- { if (PirateShip[i] < twentyPercnt)
- { counter++; }
- }
- if (counter > 0)
- { Console.WriteLine($"{counter} sections need repair."); }
- }
- }
- if (PrintFullStatus)
- {
- int sumPirat = PirateShip.Sum();
- int WarShipsum = WarShip.Sum();
- Console.WriteLine($"Pirate ship status: {sumPirat}");
- Console.WriteLine($"Warship status: {WarShipsum}");
- }
- }
- static List<int> GetDefendShip(List<int> pirateShip, int startIndex, int endIndex, int damage)
- {if (startIndex <= endIndex)
- {
- for (int i = startIndex; i <= endIndex; i++)
- {
- pirateShip[i] -= damage;
- }
- }
- return pirateShip;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement