Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Task6
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] weapons = new string[0];
  14.             string weapon = "";
  15.             string command = "";
  16.  
  17.             while(command != "/exit")
  18.             {
  19.  
  20.                 Console.WriteLine("Введите команду:");
  21.                 Console.WriteLine("\n/add - добавить новое оружие\n/equip - экипировать оружие" +
  22.                                   "\n/remove - удалить оружие\n/exit - выход из арсенала");
  23.  
  24.                 command = Console.ReadLine();
  25.  
  26.                 if(command == "/add")
  27.                 {
  28.                     Console.WriteLine("Введите название оружия:");
  29.                     command = Console.ReadLine();
  30.  
  31.                     weapons = Add(weapons, command);
  32.  
  33.                     Console.Clear();
  34.                 }
  35.                 else if(command == "/equip")
  36.                 {
  37.                     Console.WriteLine("Какое оружие экипировать:");
  38.                     command = Console.ReadLine();
  39.  
  40.                     weapon = Equip(weapons, command);
  41.  
  42.                     Console.Clear();
  43.  
  44.                 }
  45.                 else if(command == "/remove")
  46.                 {
  47.                     Console.WriteLine("Введите название оружия для удаления:");
  48.                     command = Console.ReadLine();
  49.  
  50.                     weapons = Remove(weapons, command);
  51.  
  52.                     Console.Clear();
  53.                 }
  54.                 else
  55.                 {
  56.                     Console.Clear();
  57.                 }
  58.  
  59.                 Show(weapon);
  60.                 ShowAll(weapons);
  61.             }
  62.  
  63.         }
  64.  
  65.         static string[] Add(string[] array, string element)
  66.         {
  67.             string[] tempArray = new string[array.Length + 1];
  68.  
  69.             for (int i = 0; i < array.Length; i++)
  70.             {
  71.                 tempArray[i] = array[i];
  72.             }
  73.  
  74.             tempArray[tempArray.Length - 1] = element;
  75.  
  76.             return tempArray;
  77.         }
  78.  
  79.         static string Equip(string[] array, string element)
  80.         {
  81.             for (int i = 0; i < array.Length; i++)
  82.             {
  83.                 if (array[i] == element)
  84.                     return element;
  85.             }
  86.  
  87.             return "Такого оружия нет!";
  88.         }
  89.  
  90.         static string[] Remove(string[] array, string element)
  91.         {
  92.             string[] tempArray = new string[array.Length - 1];
  93.             int temp = 1;
  94.  
  95.             for (int i = 0; i < tempArray.Length; i++)
  96.             {
  97.                 if(array[i] != element)
  98.                 {
  99.                     tempArray[i] = array[i];
  100.                 }
  101.                 else
  102.                 {
  103.                     temp = i;
  104.                     break;
  105.                 }
  106.             }
  107.  
  108.             for (int i = temp; i < array.Length - 1; i++)
  109.             {
  110.                 tempArray[i] = array[i + 1];
  111.             }
  112.  
  113.             return tempArray;
  114.         }
  115.  
  116.         static void Show(string element, int left = 40, int top = 0)
  117.         {
  118.             Console.SetCursorPosition(left, top);
  119.             Console.WriteLine($"Экипированное оружие: {element}");
  120.             Console.SetCursorPosition(0, 0);
  121.         }
  122.  
  123.         static void ShowAll(string[] array, int left = 50, int top = 5)
  124.         {
  125.             Console.SetCursorPosition(left, top);
  126.  
  127.             for (int i = 0; i < array.Length; i++)
  128.             {
  129.                 Console.WriteLine(array[i]);
  130.                 Console.SetCursorPosition(left, ++top);
  131.             }
  132.  
  133.             Console.SetCursorPosition(0, 0);
  134.         }
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement