Advertisement
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 Status { get; private set; }
- public Gamer(string nickname, int level, bool status)
- {
- _nickname = nickname;
- _level = level;
- Status = status;
- }
- public void ShowInfo()
- {
- string state = "активный";
- if (Status == false)
- {
- state = "предан анафеме";
- }
- Console.WriteLine($"{_nickname} - уровень {_level}, статус {state}");
- }
- public void ChangeStatus(bool status)
- {
- Status = status;
- }
- }
- 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, true));
- Console.Write($"\nдобавлен игрок: ");
- _gamers[_gamers.Count - 1].ShowInfo();
- }
- public void DeleteRecord()
- {
- int index;
- bool isLegalNumber = GetLegalNumber(out index);
- if (isLegalNumber)
- {
- _gamers[index - 1].ShowInfo();
- Console.WriteLine($"запись удалена");
- _gamers.RemoveAt(index - 1);
- }
- }
- public void BanGamer()
- {
- int index;
- bool isLegalNumber = GetLegalNumber(out index);
- if (isLegalNumber)
- {
- _gamers[index - 1].ChangeStatus(false);
- Console.Write($"статус изменен: ");
- _gamers[index - 1].ShowInfo();
- }
- }
- public void UnBanGamer()
- {
- int index;
- bool isLegalNumber = GetLegalNumber(out index);
- if (isLegalNumber)
- {
- _gamers[index - 1].ChangeStatus(true);
- Console.Write($"статус изменен: ");
- _gamers[index - 1].ShowInfo();
- }
- }
- private bool GetLegalNumber(out int index)
- {
- int number;
- index = 0;
- int limit = _gamers.Count;
- if (ReadInt(out number))
- {
- index = number;
- }
- bool isLegalRange = (index > 0 && index <= limit);
- if (isLegalRange == false)
- {
- Console.WriteLine($"ошибка ввода числа");
- }
- return isLegalRange;
- }
- private bool ReadInt(out int number)
- {
- bool result = false;
- Console.Write($"Введите порядковый номер игрока: ");
- result = int.TryParse(Console.ReadLine(), out number);
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement