Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System;
- namespace ConsoleApp5
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> pirateStatus = Console.ReadLine().Split('>').Select(int.Parse).ToList();
- List<int> warshipStatus = Console.ReadLine().Split('>').Select(int.Parse).ToList();
- int maxHealth = int.Parse(Console.ReadLine());
- int currentValue = 0; int currentHealth = 0; int currentIndex = 0; int damage = 0;
- string command = ""; var array = command.Split();
- bool sunken1 = false;
- bool sunken2 = false;
- for (int i = 1; i < pirateStatus.Count - 1; i++)
- {
- for (int k = 1; k < warshipStatus.Count - 1; k++)
- {
- if (sunken1 == true)
- {
- break;
- }
- else if (sunken2 == true)
- {
- break;
- }
- command = Console.ReadLine();
- double sum1 = pirateStatus.Sum(x => Convert.ToInt32(x));
- double sum2 = warshipStatus.Sum(x => Convert.ToInt32(x));
- array = command.Split();
- if (array[0] == "Fire")
- {
- int index = int.Parse(array[1]);
- damage = int.Parse(array[2]);
- if (damage < maxHealth)
- {
- if (index <= warshipStatus.Count)
- {
- currentValue = warshipStatus.ElementAt(index);
- currentHealth = currentValue - damage;
- if (currentValue - damage <= 0)
- {
- Console.WriteLine("You won! The enemy ship has sunken.");
- sunken1 = true;
- break;
- }
- else
- {
- warshipStatus.RemoveAt(index);
- warshipStatus.Insert(index, currentHealth);
- }
- }
- }
- }
- else if (array[0] == "Defend")
- {
- if (int.Parse(array[1]) <= pirateStatus.Count && int.Parse(array[2]) <= pirateStatus.Count)
- {
- int startIndex = int.Parse(array[1]);
- int endIndex = int.Parse(array[2]);
- for (int j = startIndex; j <= endIndex; j++)
- {
- damage = int.Parse(array[3]);
- currentValue = pirateStatus.ElementAt(j);
- currentHealth = currentValue - damage;
- if (currentValue - damage <= 0)
- {
- Console.WriteLine("You lost! The pirate ship has sunken.");
- sunken2 = true;
- break;
- }
- else
- {
- pirateStatus.RemoveAt(j);
- pirateStatus.Insert(j, currentHealth);
- }
- }
- }
- }
- else if (array[0] == "Repair")
- {
- if (int.Parse(array[1]) <= pirateStatus.Count - 1 && int.Parse(array[2]) <= maxHealth)
- {
- currentIndex = int.Parse(array[1]);
- int repHealth = int.Parse(array[2]);
- currentValue = pirateStatus.ElementAt(currentIndex);
- if (currentValue + repHealth > maxHealth)
- {
- currentHealth = maxHealth;
- }
- else
- {
- currentHealth = currentValue + repHealth;
- }
- pirateStatus.RemoveAt(currentIndex);
- pirateStatus.Insert(currentIndex, currentHealth);
- }
- }
- else if (array[0] == "Status")
- {
- double condition = maxHealth * 0.20;
- int sectorsForRepair = 0;
- for (int y = 0; y < pirateStatus.Count; y++)
- {
- if (pirateStatus.ElementAt(y) < condition)
- {
- sectorsForRepair++;
- }
- }
- Console.WriteLine($"{sectorsForRepair} sections need repair.");
- }
- if (command == "Retire")
- {
- Console.WriteLine($"Pirate ship status: {sum1}");
- Console.WriteLine($"Warship status: {sum2}");
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement