zaryana

ManOWar

Feb 28th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.16 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace ManOWar
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] pirateShip = Console.ReadLine().Split(">").Select(int.Parse).ToArray();
  12.             int[] warShip = Console.ReadLine().Split(">").Select(int.Parse).ToArray();
  13.             int maxHealth = int.Parse(Console.ReadLine());
  14.  
  15.             string command;
  16.             while ((command = Console.ReadLine()) != "Retire")
  17.             {
  18.                 string[] commandArgs = command.Split(' ').ToArray();
  19.                 string commandType = commandArgs[0];
  20.  
  21.                 if (commandType == "Fire")
  22.                 {
  23.                     int index = int.Parse(commandArgs[1]);
  24.                     int damage = int.Parse(commandArgs[2]);
  25.  
  26.                     if (index >= 0 && index < warShip.Length)
  27.                     {
  28.                         warShip[index] -= damage;
  29.  
  30.                         if (warShip[index] <= 0)
  31.                         {
  32.                             Console.WriteLine($"You won! The enemy ship has sunken.");
  33.                             return;
  34.                         }
  35.                         else
  36.                         {
  37.                             continue;
  38.                         }
  39.                     }
  40.                     else
  41.                     {
  42.                         continue;
  43.                     }
  44.                 }
  45.                 if (commandType == "Defend")
  46.                 {
  47.                     int startIndex = int.Parse(commandArgs[1]);
  48.                     int endIndex = int.Parse(commandArgs[2]);
  49.                     int damage = int.Parse(commandArgs[3]);
  50.  
  51.                     if (startIndex < 0 || endIndex >= pirateShip.Length)
  52.                     {
  53.                         continue;
  54.                     }
  55.                     else
  56.                     {
  57.                         for (int i = startIndex; i <= endIndex; i++)
  58.                         {
  59.                             pirateShip[i] -= damage;
  60.  
  61.                             if (pirateShip[i] <= 0)
  62.                             {
  63.                                 Console.WriteLine($"You lost! The pirate ship has sunken.");
  64.                                 return;
  65.                             }
  66.                             else
  67.                             {
  68.                                 continue;
  69.                             }
  70.                         }
  71.                     }
  72.                 }
  73.                 if (commandType == "Repair")
  74.                 {
  75.                     int index = int.Parse(commandArgs[1]);
  76.                     int health = int.Parse(commandArgs[2]);
  77.  
  78.                     if (index >=0 && index < pirateShip.Length)
  79.                     {
  80.                         pirateShip[index] += health;
  81.  
  82.                         if (pirateShip[index] > maxHealth)
  83.                         {
  84.                             pirateShip[index] = maxHealth;
  85.                         }
  86.                         else
  87.                         {
  88.                             continue;
  89.                         }
  90.                     }
  91.                     else
  92.                     {
  93.                         continue;
  94.                     }
  95.                 }
  96.                 if (commandType == "Status")
  97.                 {
  98.                     int count = 0;
  99.  
  100.                     for (int i = 0; i < pirateShip.Length; i++)
  101.                     {
  102.                         double repairNeeded = maxHealth / 5;
  103.                        
  104.                         if (pirateShip[i] < repairNeeded)
  105.                         {
  106.                             count++;
  107.                         }
  108.                         else
  109.                         {
  110.                             continue;
  111.                         }
  112.                     }
  113.                     Console.WriteLine($"{count} sections need repair.");
  114.                 }
  115.             }
  116.             int sumPirateShip = pirateShip.Sum();
  117.             int sumWarShip = warShip.Sum();
  118.  
  119.             Console.WriteLine($"Pirate ship status: {sumPirateShip}");
  120.             Console.WriteLine($"Warship status: {sumWarShip}");
  121.         }
  122.     }
  123. }
Add Comment
Please, Sign In to add comment