Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Classes
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandAddPlayer = "1";
- const string CommandRemovePlayer = "2";
- const string CommandBannPlayer = "3";
- const string CommandUnbannPlayer = "4";
- const string CommandShowAllPlayers = "5";
- const string CommandExit = "0";
- bool isRunning = true;
- Datebase datebase = new Datebase();
- while (isRunning)
- {
- Console.WriteLine($"Введите команду:\n" +
- $"{CommandAddPlayer} - добавить игрока\n" +
- $"{CommandRemovePlayer} - удалить игрока\n" +
- $"{CommandBannPlayer} - забанить игрока по номеру\n" +
- $"{CommandUnbannPlayer} - разбанить игрока по номеру\n" +
- $"{CommandShowAllPlayers} - показать всех игроков\n" +
- $"{CommandExit} - выход\n");
- string userCommand = Console.ReadLine();
- switch (userCommand)
- {
- case CommandAddPlayer:
- datebase.AddPlayer();
- break;
- case CommandRemovePlayer:
- datebase.RemovePlayer();
- break;
- case CommandBannPlayer:
- datebase.BannPlayer();
- break;
- case CommandUnbannPlayer:
- datebase.UnbannPlayer();
- break;
- case CommandShowAllPlayers:
- datebase.ShowAllPlayers();
- break;
- case CommandExit:
- isRunning = false;
- break;
- default:
- Console.WriteLine("Повторите ввод команды");
- break;
- }
- Console.Clear();
- }
- }
- }
- class Datebase
- {
- private List<Player> _player = new List<Player>();
- public void AddPlayer()
- {
- Console.WriteLine("Введите имя");
- string nickName = Console.ReadLine();
- Console.WriteLine("Введите номер");
- bool haveNumber = int.TryParse(Console.ReadLine(), out int number);
- Console.WriteLine("Введите уровень");
- bool haveLevel = int.TryParse(Console.ReadLine(), out int level);
- string signBaned = "0";
- string signUnbaned = "1";
- Console.WriteLine($"Статус игрока ({signBaned} - если забанен, {signUnbaned} - если доступен)");
- bool isBanned = false;
- bool haveStatus = true;
- string userInput = Console.ReadLine();
- if (userInput == signBaned)
- isBanned = true;
- else if (userInput == signUnbaned)
- isBanned = false;
- else
- haveStatus = false;
- foreach (Player player in _player)
- {
- if (player.Number == number)
- {
- Console.WriteLine("Номер не уникален");
- Console.ReadKey();
- haveNumber = false;
- }
- }
- if (haveNumber == true && haveLevel == true && haveStatus == true)
- {
- _player.Add(new Player(nickName, number, level, isBanned));
- }
- else
- {
- Console.WriteLine("Неверный ввод, для продолжения нажмите что нибудь");
- Console.ReadKey();
- }
- }
- public void RemovePlayer()
- {
- Console.WriteLine("Введите номер игрока запись о котором нужно удалить");
- if (TryGetPlayer(out Player player))
- _player.Remove(player);
- }
- public void BannPlayer()
- {
- Console.WriteLine("Введите номер игрока которого нужно забанить");
- if (TryGetPlayer(out Player player))
- player.Ban();
- }
- public void UnbannPlayer()
- {
- Console.WriteLine("Введите номер игрока которого нужно разабанить");
- if (TryGetPlayer(out Player player))
- player.Unban();
- }
- public void ShowAllPlayers()
- {
- foreach (Player player in _player)
- {
- string status;
- if (player.IsBanned == true)
- status = "Забанен";
- else
- status = "Свободен";
- Console.WriteLine($"Ник: {player.NickName} Номер: {player.Number} Уровень: {player.Level} Статус: {status}");
- }
- Console.ReadKey();
- }
- private bool TryGetPlayer(out Player player)
- {
- int.TryParse(Console.ReadLine(), out int number);
- foreach (Player findedPlayer in _player)
- {
- if (findedPlayer.Number == number)
- {
- player = findedPlayer;
- return true;
- }
- }
- Console.WriteLine("Нет такого номера");
- Console.ReadKey();
- player = null;
- return false;
- }
- }
- class Player
- {
- public Player(string nickName, int number, int level, bool isBanned)
- {
- NickName = nickName;
- Number = number;
- Level = level;
- IsBanned = isBanned;
- }
- public string NickName { get; private set; }
- public int Number { get; private set; }
- public int Level { get; private set; }
- public bool IsBanned { get; private set; }
- public void Ban()
- {
- IsBanned = true;
- }
- public void Unban()
- {
- IsBanned = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement