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