Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Task7
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.SetWindowSize(120, 40);
  13.  
  14.             string command = "";
  15.  
  16.             string[] weapons = new string[0];
  17.             int[] damages = new int[0];
  18.             int[] rates = new int[0];
  19.  
  20.             string currentWepon = "";
  21.             int currentIndex = 0;
  22.  
  23.             while (command != "/exit")
  24.             {
  25.                 int line = 8;
  26.  
  27.                 Console.WriteLine("Введите команду:");
  28.                 Console.WriteLine("\n/add - добавить новое оружие\n/equip - экипировать оружие" +
  29.                                   "\n/remove - удалить оружие\n/exit - выход из арсенала");
  30.  
  31.                 command = Console.ReadLine().ToLower();
  32.  
  33.                 if (command == "/add")
  34.                 {
  35.                     string[] tempWeapons = new string[weapons.Length + 1];
  36.                     int[] tempDamages = new int[weapons.Length + 1];
  37.                     int[] tempRates = new int[weapons.Length + 1];
  38.                     for (int i = 0; i < weapons.Length; i++)
  39.                     {
  40.                         tempWeapons[i] = weapons[i];
  41.                         tempDamages[i] = damages[i];
  42.                         tempRates[i] = rates[i];
  43.                     }
  44.  
  45.                     Console.WriteLine("Введите название оружия:");
  46.                     tempWeapons[tempWeapons.Length - 1] = Console.ReadLine();
  47.  
  48.                     Console.WriteLine($"Какой урон будет наносить {tempWeapons[tempWeapons.Length - 1]}:");
  49.                     tempDamages[tempDamages.Length - 1] = Convert.ToInt32(Console.ReadLine());
  50.  
  51.                     Console.WriteLine($"Какая скорострельность у {tempWeapons[tempWeapons.Length - 1]}:");
  52.                     tempRates[tempRates.Length - 1] = Convert.ToInt32(Console.ReadLine());
  53.  
  54.                     weapons = tempWeapons;
  55.                     damages = tempDamages;
  56.                     rates = tempRates;
  57.                 }
  58.                 else if (command == "/equip")
  59.                 {
  60.                     Console.WriteLine("Какое оружие экипировать:");
  61.                     currentWepon = Console.ReadLine().ToLower();
  62.  
  63.                     for (int i = 0; i < weapons.Length; i++)
  64.                     {
  65.                         if (currentWepon == weapons[i])
  66.                         {
  67.                             currentIndex = i;
  68.                         }
  69.                     }
  70.                 }
  71.                 else if (command == "/remove" && weapons.Length > 0)
  72.                 {
  73.                     Console.WriteLine("Какое оружие удалить из инвентаря:");
  74.                     string removeWeapon = Console.ReadLine();
  75.  
  76.                     string[] tempWeapons = new string[weapons.Length - 1];
  77.                     int[] tempDamages = new int[weapons.Length - 1];
  78.                     int[] tempRates = new int[weapons.Length - 1];
  79.                     int tempIndex = 0;
  80.  
  81.                     for (int i = 0; i < weapons.Length - 1; i++)
  82.                     {
  83.                         if (weapons[i] != removeWeapon)
  84.                         {
  85.                             tempWeapons[i] = weapons[i];
  86.                             tempDamages[i] = damages[i];
  87.                             tempRates[i] = rates[i];
  88.  
  89.                             if(i == weapons.Length - 2)
  90.                             {
  91.                                 tempIndex = weapons.Length - 1;
  92.                             }
  93.                         }
  94.                         else
  95.                         {
  96.                             tempIndex = i;
  97.                             break;
  98.                         }
  99.                     }
  100.  
  101.                     if (weapons[weapons.Length - 1] != removeWeapon)
  102.                     {
  103.                         for (int j = tempIndex; j < weapons.Length - 1; j++)
  104.                         {
  105.                             tempWeapons[j] = weapons[j + 1];
  106.                             tempDamages[j] = damages[j + 1];
  107.                             tempRates[j] = rates[j + 1];
  108.                         }
  109.                     }
  110.  
  111.                     if (weapons.Length > 0 && currentIndex != 0 && tempIndex <= currentIndex)
  112.                         currentIndex--;
  113.  
  114.                     weapons = tempWeapons;
  115.                     damages = tempDamages;
  116.                     rates = tempRates;
  117.                 }
  118.  
  119.                 Console.Clear();
  120.  
  121.                 Console.ForegroundColor = ConsoleColor.Red;
  122.                 Console.SetCursorPosition(55, 0);
  123.                 Console.WriteLine("PARATROOPER - ARSENAL");
  124.  
  125.                 if(weapons.Length > 0)
  126.                 {
  127.                     Console.SetCursorPosition(50, 2);
  128.                     Console.WriteLine("Экипировано: " + weapons[currentIndex]);
  129.  
  130.                     Console.SetCursorPosition(50, 3);
  131.                     Console.WriteLine("Урон - " + damages[currentIndex]);
  132.  
  133.                     Console.SetCursorPosition(50, 4);
  134.                     Console.WriteLine("Скорострельность - " + rates[currentIndex] + " выстрелов в минуту");
  135.                 }
  136.  
  137.                 Console.SetCursorPosition(50, 7);
  138.                 Console.ForegroundColor = ConsoleColor.Gray;
  139.  
  140.                 Console.WriteLine("Инвентарь:");
  141.                 for (int i = 0; i < weapons.Length; i++)
  142.                 {
  143.                     Console.SetCursorPosition(50, ++line);
  144.                     Console.ForegroundColor = ConsoleColor.Green;
  145.                     Console.WriteLine($"| {weapons[i]} | damage-{damages[i]} | rate-{rates[i]} |");
  146.                     Console.ForegroundColor = ConsoleColor.Gray;
  147.                 }
  148.  
  149.                 Console.SetCursorPosition(0, 0);
  150.             }
  151.         }
  152.     }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement