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 PlayerDatabase_02
- {
- class Program
- {
- static void Main(string[] args)
- {
- Register register = new Register(new List<Gamer>());
- bool isOpen = true;
- string userInput;
- while (isOpen)
- {
- Console.WriteLine($"админка управления игроками");
- Console.WriteLine($"\n0 - Список игроков\n1 - Добавить игрока\n2 - Заблокировать игрока\n3 - Разблокировать игрока\n4 - Удалить игрока\n5 - Выход");
- Console.Write($"\nВведите номер команды: ");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "0":
- Console.WriteLine($"Список игроков:\n");
- register.ShowRecords();
- break;
- case "1":
- Console.WriteLine($"Добавление игрока\n");
- register.AddRecord();
- break;
- case "2":
- Console.WriteLine($"Блокирование игрока");
- register.BanGamer();
- break;
- case "3":
- Console.WriteLine($"Разблокирование игрока");
- register.UnbanGamer();
- break;
- case "4":
- Console.WriteLine($"Удаление игрока\n");
- register.DeleteRecord();
- break;
- case "5":
- Console.WriteLine($"\nВыход из программы");
- isOpen = false;
- break;
- }
- Console.Write($"\nлюбую для продолжения... ");
- Console.ReadKey();
- Console.Clear();
- }
- }
- }
- class Gamer
- {
- private string _nickname;
- private int _level;
- public bool IsBanned { get; private set; }
- public Gamer(string nickname, int level, bool isBanned)
- {
- _nickname = nickname;
- _level = level;
- IsBanned = isBanned;
- }
- public void ShowInfo()
- {
- string status = "не числиться";
- if (IsBanned)
- {
- status = "находится";
- }
- Console.WriteLine($"{_nickname} - {_level} уровень, {status} в черном списке");
- }
- public void Ban()
- {
- IsBanned = true;
- }
- public void Unan()
- {
- IsBanned = false;
- }
- }
- class Register
- {
- private List<Gamer> _gamers;
- public Register(List<Gamer> gamers)
- {
- _gamers = gamers;
- }
- public void ShowRecords()
- {
- for (int i = 0; i < _gamers.Count; i++)
- {
- Console.Write($"{i + 1}. ");
- _gamers[i].ShowInfo();
- }
- if (_gamers.Count == 0)
- {
- Console.WriteLine($"список пуст");
- }
- }
- public void AddRecord()
- {
- Console.Write($"Введите имя игрока: ");
- string nickname = Console.ReadLine();
- _gamers.Add(new Gamer(nickname, 1, false));
- Console.Write($"\nдобавлен игрок: ");
- _gamers[_gamers.Count - 1].ShowInfo();
- }
- public void DeleteRecord()
- {
- int index;
- bool isLegalNumber = TryGetIndex(out index);
- if (isLegalNumber)
- {
- _gamers[index - 1].ShowInfo();
- Console.WriteLine($"запись удалена");
- _gamers.RemoveAt(index - 1);
- }
- }
- public void BanGamer()
- {
- int index;
- if (TryGetIndex(out index))
- {
- _gamers[index - 1].Ban();
- }
- }
- public void UnbanGamer()
- {
- int index;
- if (TryGetIndex(out index))
- {
- _gamers[index - 1].Unan();
- }
- }
- private bool TryGetIndex(out int index)
- {
- int number;
- index = 0;
- int limit = _gamers.Count;
- if (TryReadInt(out number))
- {
- index = number;
- }
- bool isLegalRange = (index > 0 && index <= limit);
- if (isLegalRange == false)
- {
- Console.WriteLine($"ошибка ввода числа");
- }
- return isLegalRange;
- }
- private bool TryReadInt(out int number)
- {
- bool result = false;
- Console.Write($"Введите порядковый номер игрока: ");
- result = int.TryParse(Console.ReadLine(), out number);
- return result;
- }
- }
- }
Add Comment
Please, Sign In to add comment