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 ConsoleApp9
- {
- class Program
- {
- static void Main()
- {
- bool work = true;
- PlayerList playerList = new PlayerList(new BanList[]
- {
- new BanList(new Player("Nemesis", 23), false),
- new BanList(new Player("Alex", 45), false),
- new BanList(new Player("Nagibator2010", 78), false),
- new BanList(new Player("Pinguin", 56), false),
- new BanList(new Player("Noob", 5), false),
- });
- while (work)
- {
- Console.Clear();
- playerList.ShowAllPlayers();
- Console.WriteLine();
- Console.WriteLine("Вы берите действие:\nДля добавление нового игрока - нажмите 1\nДля бана игрока - нажмите 2\nДля разбана игрока - нажмите 3\nДля удаления игрока - нажмите 4\nДля выхода - нажмите 5");
- int userInput = Convert.ToInt32(Console.ReadLine());
- switch (userInput)
- {
- case 1:
- AddNewPlayer(ref playerList);
- break;
- case 2:
- CheckUserInput(ref userInput, "Бана", playerList);
- break;
- case 3:
- CheckUserInput(ref userInput, "Разбана", playerList);
- break;
- case 4:
- DelelePlayer(ref playerList);
- break;
- case 5:
- work = false;
- break;
- default:
- Console.WriteLine("Вы ввели несуществующую команду. Попробуйте еще раз.");
- break;
- }
- Console.WriteLine("Вы вышли из админской программы!");
- }
- }
- static void CheckUserInput(ref int userInput, string action, PlayerList playerList)
- {
- Console.WriteLine($"Введите номер игрока для {action}");
- userInput = Convert.ToInt32(Console.ReadLine());
- if (userInput <= playerList.BanLists.Length - 1)
- {
- if (action == "Бана")
- {
- playerList.BanLists[userInput].Ban();
- }
- else if (action == "Разбана")
- {
- playerList.BanLists[userInput].DisBan();
- }
- }
- else
- {
- Console.WriteLine("Вы ввели несуществующего игрока");
- }
- }
- static void AddNewPlayer(ref PlayerList playerList)
- {
- Console.Write("Введите имя нового игрока: ");
- string newPlayerName = Console.ReadLine();
- Console.Write("Введите уровень нового игрока: ");
- int newPlayerLevel = Convert.ToInt32(Console.ReadLine());
- PlayerList tempPlayerList = new PlayerList(new BanList[playerList.BanLists.Length+1]);
- for (int i = 0; i < playerList.BanLists.Length; i++)
- {
- tempPlayerList.BanLists[i] = playerList.BanLists[i];
- }
- tempPlayerList.BanLists[tempPlayerList.BanLists.Length - 1] = new BanList(new Player(newPlayerName,newPlayerLevel),false);
- playerList = tempPlayerList;
- }
- static void DelelePlayer(ref PlayerList playerList)
- {
- Console.Write("Введите номер игрока, которого необходимо удалить: ");
- int deletePlayer = Convert.ToInt32(Console.ReadLine());
- PlayerList tempPlayerList = new PlayerList(new BanList[playerList.BanLists.Length - 1]);
- for (int i = 0; i < tempPlayerList.BanLists.Length; i++)
- {
- if (i >= deletePlayer)
- {
- tempPlayerList.BanLists[i] = playerList.BanLists[i + 1];
- }
- else
- {
- tempPlayerList.BanLists[i] = playerList.BanLists[i];
- }
- }
- playerList = tempPlayerList;
- }
- }
- class Player
- {
- public string PlayerName { get; private set; }
- public int Level { get; private set; }
- public Player(string user, int level)
- {
- PlayerName = user;
- Level = level;
- }
- }
- class PlayerList
- {
- public BanList[] BanLists;
- public PlayerList(BanList[] banLists)
- {
- BanLists = banLists;
- }
- public void ShowAllPlayers()
- {
- for (int i = 0; i < BanLists.Length; i++)
- {
- BanLists[i].ShowInfo(i);
- }
- }
- }
- class BanList
- {
- public Player Player;
- private bool _isBanned;
- public BanList(Player player, bool isBanned)
- {
- Player = player;
- _isBanned = isBanned;
- }
- public void ShowInfo(int i)
- {
- Console.WriteLine($"Номер игрока: {i} | Ник игрока: {Player.PlayerName} | Уровень игрока: {Player.Level} |Забанен: {_isBanned} |");
- }
- public void Ban()
- {
- _isBanned = true;
- Console.WriteLine($"Игрок - {Player.PlayerName} - ЗАБАНЕН");
- }
- public void DisBan()
- {
- _isBanned = false;
- Console.WriteLine($"Игрок - {Player.PlayerName} - Разбанен");
- }
- }
- }
Add Comment
Please, Sign In to add comment