Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Task6
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] weapons = new string[0];
- string weapon = "";
- string command = "";
- while(command != "/exit")
- {
- Console.WriteLine("Введите команду:");
- Console.WriteLine("\n/add - добавить новое оружие\n/equip - экипировать оружие" +
- "\n/remove - удалить оружие\n/exit - выход из арсенала");
- command = Console.ReadLine();
- if(command == "/add")
- {
- Console.WriteLine("Введите название оружия:");
- command = Console.ReadLine();
- weapons = Add(weapons, command);
- Console.Clear();
- }
- else if(command == "/equip")
- {
- Console.WriteLine("Какое оружие экипировать:");
- command = Console.ReadLine();
- weapon = Equip(weapons, command);
- Console.Clear();
- }
- else if(command == "/remove")
- {
- Console.WriteLine("Введите название оружия для удаления:");
- command = Console.ReadLine();
- weapons = Remove(weapons, command);
- Console.Clear();
- }
- else
- {
- Console.Clear();
- }
- Show(weapon);
- ShowAll(weapons);
- }
- }
- static string[] Add(string[] array, string element)
- {
- string[] tempArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[tempArray.Length - 1] = element;
- return tempArray;
- }
- static string Equip(string[] array, string element)
- {
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] == element)
- return element;
- }
- return "Такого оружия нет!";
- }
- static string[] Remove(string[] array, string element)
- {
- string[] tempArray = new string[array.Length - 1];
- int temp = 1;
- for (int i = 0; i < tempArray.Length; i++)
- {
- if(array[i] != element)
- {
- tempArray[i] = array[i];
- }
- else
- {
- temp = i;
- break;
- }
- }
- for (int i = temp; i < array.Length - 1; i++)
- {
- tempArray[i] = array[i + 1];
- }
- return tempArray;
- }
- static void Show(string element, int left = 40, int top = 0)
- {
- Console.SetCursorPosition(left, top);
- Console.WriteLine($"Экипированное оружие: {element}");
- Console.SetCursorPosition(0, 0);
- }
- static void ShowAll(string[] array, int left = 50, int top = 5)
- {
- Console.SetCursorPosition(left, top);
- for (int i = 0; i < array.Length; i++)
- {
- Console.WriteLine(array[i]);
- Console.SetCursorPosition(left, ++top);
- }
- Console.SetCursorPosition(0, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement