Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberPlayers = 1;
- bool isCointinue = true;
- DataBase dataBase = new DataBase();
- while (isCointinue)
- {
- int userNumber = 0;
- Console.ReadKey();
- Console.Clear();
- Console.WriteLine("Меню: \n1.Добавить игрока\n2.Забанить игрока\n3.Разбанить игрока\n4.Удалить игрока\n5.Посмотреть информацию о игроках\n6.Выход");
- string userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- Console.Write("\nВведите имя: ");
- string userName = Console.ReadLine();
- dataBase.AddPLayer(numberPlayers, userName);
- numberPlayers++;
- Console.WriteLine("Игрок добавлен");
- break;
- case "2":
- try
- {
- Console.Write("\nВведите порядковый номер игрока: ");
- userNumber = Convert.ToInt32(Console.ReadLine());
- dataBase.SetBanFlag(userNumber,true);
- Console.WriteLine("Игрок забанен");
- }
- catch (Exception)
- {
- Console.WriteLine("Указан не правильный номер игрока");
- }
- break;
- case "3":
- Console.Write("\nВведите порядковый номер игрока: ");
- try
- {
- userNumber = Convert.ToInt32(Console.ReadLine());
- dataBase.SetBanFlag(userNumber, false);
- Console.WriteLine("Игрок разбанен");
- }
- catch (Exception)
- {
- Console.WriteLine("Указан не правильный номер игрока");
- }
- break;
- case "4":
- try
- {
- Console.WriteLine("Введите порядковый номер игрока: ");
- userNumber = Convert.ToInt32(Console.ReadLine());
- dataBase.RemovePlayer(userNumber);
- Console.WriteLine("Игрок удален");
- }
- catch (Exception)
- {
- Console.WriteLine("Указан не правильный номер игрока");
- }
- break;
- case "5":
- try
- {
- Console.WriteLine($"Введите порядковый номер игрока. Сейчас игроков: {dataBase.GetCountPlayers()} ");
- userNumber = Convert.ToInt32(Console.ReadLine());
- dataBase.ShowInfo(userNumber);
- }
- catch (Exception)
- {
- Console.WriteLine("Указан не правильный номер игрока");
- }
- break;
- case "6":
- isCointinue = false;
- break;
- default:
- Console.WriteLine("Нет такой команды");
- break;
- }
- }
- }
- class Player
- {
- private int _number;
- private string _name;
- private int _lvl;
- private bool _isBun;
- public Player(int number, string name, int lvl = 1, bool isBan = false)
- {
- _number = number;
- _name = name;
- _lvl = lvl;
- _isBun = isBan;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Номер: {_number}\nИмя: {_name}\nУровень: {_lvl}\nБан: {_isBun}");
- }
- public void SetIsBun(bool flagBan)
- {
- _isBun = flagBan;
- }
- }
- class DataBase
- {
- private List<Player> _player = new List<Player>();
- public void AddPLayer(int index, string name)
- {
- _player.Add(new Player(index, name));
- }
- public void SetBanFlag(int index, bool flag)
- {
- _player[index - 1].SetIsBun(flag);
- }
- public void RemovePlayer(int index)
- {
- _player.RemoveAt(index - 1);
- }
- public int GetCountPlayers()
- {
- return _player.Count;
- }
- public void ShowInfo(int index)
- {
- _player[index - 1].ShowInfo();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment