Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CSLight
- {
- class Program
- {
- static void Main(string[] args)
- {
- const string AddPlayer = "1";
- const string BanPlayer = "2";
- const string UnbanPlayer = "3";
- const string DeletePlayer = "4";
- const string PrintAllPlayers = "5";
- const string ExitProgram = "6";
- Database database = new Database();
- bool isWorking = true;
- while (isWorking)
- {
- Console.WriteLine($"{AddPlayer})Добавить игрока.\n{BanPlayer})Забанить игрока.\n{UnbanPlayer})Разбанить игрока.\n{DeletePlayer})Удалить игрока." +
- $"\n{PrintAllPlayers})Вывести список всех игроков.\n{ExitProgram})Выход из программы.");
- string userInput = Console.ReadLine();
- switch (userInput)
- {
- case AddPlayer:
- database.AddPlayer();
- break;
- case BanPlayer:
- database.BanPlayer();
- break;
- case UnbanPlayer:
- database.UnbanPlayer();
- break;
- case DeletePlayer:
- database.DeletePlayer();
- break;
- case PrintAllPlayers:
- database.PrintAllPlayers();
- break;
- case ExitProgram:
- isWorking = false;
- break;
- default:
- Console.WriteLine("Неверный выбор. Попробуйте еще раз.");
- break;
- }
- }
- }
- }
- class Database
- {
- private Dictionary<int, Player> _players = new Dictionary<int, Player>();
- private int _nextId = 1;
- public void AddPlayer()
- {
- Console.WriteLine("Введите ник игрока.");
- string nickname = Console.ReadLine();
- Console.WriteLine("Введите уровень");
- int level = Convert.ToInt32(Console.ReadLine());
- Player player = new Player(_nextId, nickname, level);
- _players.Add(_nextId, player);
- _nextId++;
- Console.WriteLine($"Игрок {nickname} добавлен с ID {player.Id}");
- }
- public void BanPlayer()
- {
- Console.WriteLine("Введите уникальный номер игрока которого хотите забанить.");
- int userInput = Convert.ToInt32(Console.ReadLine());
- if (_players.TryGetValue(userInput, out var player))
- {
- player.IsBanned = true;
- Console.WriteLine($"Игрок {player.Nickname} (ID: {userInput}) забанен.");
- }
- else
- {
- Console.WriteLine($"Игрок с ID {userInput} не найден.");
- }
- }
- public void UnbanPlayer()
- {
- Console.WriteLine("Введите уникальный номер игрока которого хотите разбанить.");
- int userInput = Convert.ToInt32(Console.ReadLine());
- if (_players.TryGetValue(userInput, out var player))
- {
- player.IsBanned = false;
- Console.WriteLine($"Игрок {player.Nickname} (ID: {userInput}) разбанен.");
- }
- else
- {
- Console.WriteLine($"Игрок с ID {userInput} не найден.");
- }
- }
- public void DeletePlayer()
- {
- Console.WriteLine("Введите уникальный номер игрока которого хотите удалить.");
- int userInput = Convert.ToInt32(Console.ReadLine());
- if (_players.Remove(userInput, out var player))
- {
- Console.WriteLine($"Игрок {player.Nickname} (ID: {userInput}) удален.");
- }
- else
- {
- Console.WriteLine($"Игрок с ID {userInput} не найден.");
- }
- }
- public void PrintAllPlayers()
- {
- if (_players.Count == 0)
- {
- Console.WriteLine("В базе нет игроков.");
- }
- else
- {
- Console.WriteLine("Список игроков:");
- foreach (var player in _players.Values)
- {
- player.ShowPlayer();
- }
- }
- }
- }
- class Player
- {
- public int Id { get; private set; }
- public string Nickname { get; private set; }
- public int Level { get; private set; }
- public bool IsBanned { get; set; }
- public Player(int uniqueNumber, string nickname, int lvl, bool isBanned = false)
- {
- Id = uniqueNumber;
- Nickname = nickname;
- Level = lvl;
- IsBanned = isBanned;
- }
- public void ShowPlayer()
- {
- if (IsBanned == false)
- {
- Console.WriteLine($"ID: {Id} | Ник: {Nickname} | Уровень: {Level} | Статус: Активен");
- }
- else
- {
- Console.WriteLine($"ID: {Id} | Ник: {Nickname} | Уровень: {Level} | Статус: Забанен");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement