Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Threading;
- namespace ConsoleApp1
- {
- class Exam
- {
- static void Main(string[] args)
- {
- // fire - warship
- // defend - pirate ship
- // repair - pirate ship
- // status - both
- List<int> pirate = Console.ReadLine().Split('>').Select(int.Parse).ToList();
- List<int> war = Console.ReadLine().Split('>').Select(int.Parse).ToList();
- int maxHealth = int.Parse(Console.ReadLine());
- string[] command = Console.ReadLine().Split().ToArray();
- while (command[0] != "Retire")
- {
- if (command[0] == "Fire")
- {
- int index = int.Parse(command[1]);
- if (index >= 0 && index < war.Count)
- {
- int damage = int.Parse(command[2]);
- war[index] -= damage;
- if (war[index] <= 0)
- {
- Console.WriteLine("You won! The enemy ship has sunken.");
- break;
- }
- }
- }
- if (command[0] == "Defend")
- {
- bool won = false;
- int startIndex = int.Parse(command[1]);
- int endIndex = int.Parse(command[2]);
- if ((startIndex >= 0 && startIndex < pirate.Count) && endIndex >= 0 && endIndex < pirate.Count)
- {
- int damage = int.Parse(command[3]);
- for (int i = startIndex; i <= endIndex; i++)
- {
- pirate[i] -= damage;
- if (pirate[i] <= 0)
- {
- Console.WriteLine("You lost! The pirate ship has sunken.");
- won = true;
- break;
- }
- }
- if (won)
- {
- break;
- }
- }
- }
- if (command[0] == "Repair")
- {
- int index = int.Parse(command[1]);
- if (index >= 0 && index < pirate.Count)
- {
- int health = int.Parse(command[2]);
- pirate[index] += health;
- if (pirate[index] > maxHealth)
- {
- pirate[index] = maxHealth;
- }
- }
- }
- if (command[0] == "Status")
- {
- int count = 0;
- for (int i = 0; i < pirate.Count; i++)
- {
- if (pirate[i] < maxHealth * 0.20)
- {
- count++;
- }
- }
- Console.WriteLine($"{count} sections need repair.");
- }
- command = Console.ReadLine().Split().ToArray();
- }
- if (command[0] == "Retire")
- {
- Console.WriteLine($"Pirate ship status: {pirate.Sum()}");
- Console.WriteLine($"Warship status: {war.Sum()}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement