TheBulgarianWolf

Weaponsmith

Jan 17th, 2021
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Weaponsmith
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             List<string> weaponParts = new List<string>();
  11.             Console.WriteLine("Enter parts of a weapon's name separated by | : ");
  12.             string[] parts = Console.ReadLine().Split("|");
  13.             for(int i = 0; i < parts.Length; i++)
  14.             {
  15.                 weaponParts.Add(parts[i]);
  16.             }
  17.             Console.WriteLine("Start entering commands:");
  18.             Console.WriteLine("Move Left {index}");
  19.             Console.WriteLine("Move Right {index}");
  20.             Console.WriteLine("Check Even");
  21.             Console.WriteLine("Check Odd");
  22.             Console.WriteLine("When you are done with the commands enter \"Done\"");
  23.             string input;
  24.             while((input = Console.ReadLine()) != "Done")
  25.             {
  26.                 string[] inputInfo = input.Split(" ");
  27.                 switch (inputInfo[0])
  28.                 {
  29.                     case "Move":
  30.                         if (inputInfo[1] == "Left")
  31.                         {
  32.                             MoveLeft(int.Parse(inputInfo[2]), weaponParts);
  33.                         }
  34.                         else if(inputInfo[1] == "Right")
  35.                         {
  36.                             MoveRight(int.Parse(inputInfo[2]), weaponParts);
  37.                         }
  38.                         break;
  39.                     case "Check":
  40.                         if (inputInfo[1] == "Even")
  41.                         {
  42.                             CheckEven(weaponParts);
  43.                         }
  44.                         else if (inputInfo[1] == "Odd")
  45.                         {
  46.                             CheckOdd(weaponParts);
  47.                         }
  48.                         break;
  49.                     default:
  50.                         Console.WriteLine("Invalid operation!");
  51.                         break;
  52.                 }
  53.             }
  54.  
  55.             foreach(string element in weaponParts)
  56.             {
  57.                 Console.Write(element + " ");
  58.             }
  59.         }
  60.  
  61.         static void MoveLeft(int index,List<string> parts)
  62.         {
  63.             if(index-1 >= 0)
  64.             {
  65.                 string element = parts[index];
  66.                 parts.RemoveAt(index);
  67.                 parts.Insert(index - 1, element);
  68.             }
  69.             else
  70.             {
  71.                 Console.WriteLine("Impossible operation!");
  72.             }
  73.         }
  74.  
  75.         static void MoveRight(int index, List<string> parts)
  76.         {
  77.             if (index + 1 <= parts.Count-1)
  78.             {
  79.                 string element = parts[index];
  80.                 parts.RemoveAt(index);
  81.                 parts.Insert(index + 1, element);
  82.             }
  83.             else
  84.             {
  85.                 Console.WriteLine("Impossible operation!");
  86.             }
  87.         }
  88.  
  89.         static void CheckEven(List<string> list)
  90.         {
  91.             for(int i = 0; i < list.Count; i++)
  92.             {
  93.                 if(i%2 == 0)
  94.                 {
  95.                     Console.WriteLine(list[i]);
  96.                 }
  97.             }
  98.         }
  99.  
  100.         static void CheckOdd(List<string> list)
  101.         {
  102.             for (int i = 0; i < list.Count; i++)
  103.             {
  104.                 if (i % 2 != 0)
  105.                 {
  106.                     Console.WriteLine(list[i]);
  107.                 }
  108.             }
  109.         }
  110.     }
  111. }
Add Comment
Please, Sign In to add comment