Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Treasure_Hunt
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> pirateShip = Console.ReadLine().Split(">").Select(int.Parse).ToList();
- List<int> low = new List<int>(pirateShip);
- int counter = 0;
- int counter1 = 0;
- List<int> warShip = Console.ReadLine().Split(">").Select(int.Parse).ToList();
- int health = int.Parse(Console.ReadLine());
- int broken = 0;
- string command;
- while ((command = Console.ReadLine()) != "Retire")
- {
- string[] a = command.Split(' ').ToArray();
- if (a[0] == "Fire")
- {
- int indeex = int.Parse(a[1]);
- int fire = int.Parse(a[2]);
- if (indeex >= 0 && indeex < warShip.Count)
- {
- int d = warShip[indeex];
- int damage = d - fire;
- warShip.RemoveAt(indeex);
- warShip.Insert(indeex, damage);
- if (damage <= 0)
- {
- Console.WriteLine("You won! The enemy ship has sunken.");
- break;
- }
- }
- }
- if (a[0] == "Defend")
- {
- int startIndex = int.Parse(a[1]);
- int endIndex = int.Parse(a[2]);
- int dmg = int.Parse(a[3]);
- if (startIndex >= 0 && startIndex < pirateShip.Count && endIndex >= 0 && endIndex < pirateShip.Count && dmg >= 0)
- {
- for (int i = startIndex; i <= endIndex; i++)
- {
- int n = i;
- pirateShip[n] -= dmg;
- if (dmg >= pirateShip[i])
- {
- counter++;
- break;
- }
- }
- if (counter > 0)
- {
- Console.WriteLine("You lost! The pirate ship has sunken.");
- break;
- }
- }
- {
- }
- }
- if (a[0] == "Repair")
- {
- int healIndex = int.Parse(a[1]);
- int heal = int.Parse(a[2]);
- if (healIndex >= 0 && healIndex < pirateShip.Count && heal >= 0)
- {
- int currentBox = pirateShip[healIndex];
- if (currentBox <= health)
- {
- int potion = currentBox + heal;
- if (potion > health)
- {
- potion = health;
- }
- pirateShip.RemoveAt(healIndex);
- pirateShip.Insert(healIndex, potion);
- }
- }
- }
- if (a[0] == "Status")
- {
- double lowH = health - (health * 0.8);
- for (int i = 0; i < pirateShip.Count; i++)
- {
- if (lowH > pirateShip[i])
- {
- broken++;
- }
- }
- Console.WriteLine($"{broken} sections need repair.");
- }
- }
- int pirateResult = 0;
- int warResult = 0;
- if (counter == 0)
- {
- for (int i = 0; i < pirateShip.Count; i++)
- {
- pirateResult += pirateShip[i];
- }
- Console.WriteLine($"Pirate ship status: {pirateResult}");
- for (int i = 0; i < warShip.Count; i++)
- {
- warResult += warShip[i];
- }
- Console.WriteLine($"Warship status: {warResult}");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment