Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _10TopNumber
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] arrPirateShip = Console.ReadLine().Split(">", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int[] arrWarShip = Console.ReadLine().Split(">", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int maxHealtyCapacity = int.Parse(Console.ReadLine());
- List<int> pirateShip = new List<int>(arrPirateShip);
- List<int> warShip = new List<int>(arrWarShip);
- string command;
- bool IsWarShipBroke = false;
- bool IsPiratesShipBroke = false;
- int repireSections = 0;
- while ((command = Console.ReadLine()) != "Retire")
- {
- string[] cmdArgs = command.Split();
- IsWarShipBroke = FireMethod(warShip, IsWarShipBroke, cmdArgs);
- IsPiratesShipBroke = DefendMethod(pirateShip, IsPiratesShipBroke, cmdArgs);
- HealthIndex(maxHealtyCapacity, pirateShip, cmdArgs);
- }
- for (int i = 0; i < pirateShip.Count; i++)
- {
- if (pirateShip[i] < maxHealtyCapacity * 0.2)
- {
- repireSections++;
- }
- }
- Console.WriteLine($"{repireSections} sections need repair.");
- if (IsWarShipBroke)
- {
- Console.WriteLine("You won! The enemy ship has sunken.");
- return;
- }
- if (IsPiratesShipBroke)
- {
- Console.WriteLine("You lost! The pirate ship has sunken.");
- return;
- }
- Console.Write("Pirate ship status: ");
- Console.WriteLine(String.Join("", pirateShip.Sum()));
- Console.Write("Warship status: ");
- Console.WriteLine(String.Join("", warShip.Sum()));
- }
- private static bool DefendMethod(List<int> pirateShip, bool IsPiratesShipBroke, string[] cmdArgs)
- {
- if (cmdArgs[0] == "Defend")
- {
- int startIndex = int.Parse(cmdArgs[1]);
- int endIndex = int.Parse(cmdArgs[2]);
- int damage = int.Parse(cmdArgs[3]);
- if (startIndex >= 0 && startIndex < pirateShip.Count && endIndex >= 0 && endIndex < pirateShip.Count)
- {
- for (int i = startIndex; i <= endIndex; i++)
- {
- pirateShip[i] = pirateShip[i] - damage;
- if (pirateShip[i] <= 0)
- {
- IsPiratesShipBroke = true;
- //Console.WriteLine("You lost! The pirate ship has sunken.");
- break;
- }
- }
- }
- }
- return IsPiratesShipBroke;
- }
- private static bool FireMethod(List<int> warShip, bool IsWarShipBroke, string[] cmdArgs)
- {
- if (cmdArgs[0] == "Fire")
- {
- int index = int.Parse(cmdArgs[1]);
- int damege = int.Parse(cmdArgs[2]);
- if (index >= 0 && index < warShip.Count)
- {
- if (warShip[index] - damege > 0)
- {
- warShip[index] = warShip[index] - damege;
- }
- else
- {
- IsWarShipBroke = true;
- //Console.WriteLine("You won! The enemy ship has sunken.");
- }
- }
- }
- return IsWarShipBroke;
- }
- private static void HealthIndex(int maxHealtyCapacity, List<int> pirateShip, string[] cmdArgs)
- {
- if (cmdArgs[0] == "Repair")
- {
- int index = int.Parse(cmdArgs[1]);
- int health = int.Parse(cmdArgs[2]);
- if (index >= 0 && index < pirateShip.Count)
- {
- int healthedIndex = pirateShip[index] + health;
- if (healthedIndex > maxHealtyCapacity)
- {
- healthedIndex = maxHealtyCapacity;
- }
- pirateShip[index] = healthedIndex;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement