Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace OOP
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isExit = true;
- List<Player> player = new List<Player>();
- DataBase database = new DataBase(player);
- while (isExit == true)
- {
- Console.WriteLine("1) Добавить игрока");
- Console.WriteLine("2) Забанить игрока");
- Console.WriteLine("3) Разбанить игрока");
- Console.WriteLine("4) Удалить игрока");
- Console.WriteLine("5) Показать всех игроков");
- Console.WriteLine("6) Выйти");
- Console.Write("Выберите действие: ");
- switch (Console.ReadLine())
- {
- case "1":
- database.AddPlayer();
- break;
- case "2":
- database.BanPlayer();
- break;
- case "3":
- database.UnbanPlayer();
- break;
- case "4":
- database.RemovePlayer();
- break;
- case "5":
- database.ShowPlayersInfo();
- break;
- case "6":
- isExit = false;
- break;
- default:
- Console.WriteLine("Ошибка! Такой команды нет!");
- Console.ReadKey();
- Console.Clear();
- break;
- }
- }
- }
- }
- class Player
- {
- private string _name;
- private int _level;
- private bool _isBan;
- public Player(string name, int level, bool isBan)
- {
- _name = name;
- _level = level;
- _isBan = isBan;
- }
- public void ShowInfo(int index)
- {
- Console.Write(index + 1 + ") ");
- Console.WriteLine($"Имя игрока - {_name}, уровень игрока - {_level}, статус блокировки игрока - {_isBan}");
- }
- public void Ban()
- {
- _isBan = true;
- }
- public void Unban()
- {
- _isBan = false;
- }
- }
- class DataBase
- {
- private Player _player;
- private List<Player> _players = new List<Player>();
- private string _indexPlayer;
- private string _name;
- private int _numberPlayer;
- public DataBase(List<Player> players)
- {
- _players = players;
- }
- public void AddPlayer()
- {
- Console.Write("Введите имя игрока: ");
- _name = Console.ReadLine();
- _players.Add(new Player(_name, 1, false));
- Console.WriteLine("Игрок добавлен!");
- Console.ReadKey();
- Console.Clear();
- }
- public void RemovePlayer()
- {
- if (TryFindPlayer(out _player, "Игрок удален"))
- {
- _players.RemoveAt(_numberPlayer);
- }
- Console.ReadKey();
- Console.Clear();
- }
- public void BanPlayer()
- {
- Console.Write("Введите номер игрока, которого хотите забанить: ");
- if (TryFindPlayer(out _player, "Игрок забанен"))
- {
- _player.Ban();
- }
- Console.ReadKey();
- Console.Clear();
- }
- public void UnbanPlayer()
- {
- Console.Write("Введите номер игрока, которого хотите разабанить: ");
- if (TryFindPlayer(out _player, "Игрок разбанен"))
- {
- _player.Unban();
- }
- Console.ReadKey();
- Console.Clear();
- }
- public void ShowPlayersInfo()
- {
- for (int i = 0; i < _players.Count; i++)
- {
- _players[i].ShowInfo(i);
- }
- Console.ReadKey();
- Console.Clear();
- }
- private bool TryFindPlayer(out Player player, string message)
- {
- player = null;
- _indexPlayer = Console.ReadLine();
- if (int.TryParse(_indexPlayer, out _numberPlayer))
- {
- _numberPlayer--;
- if (_players.Count > _numberPlayer && _numberPlayer >= 0)
- {
- Console.WriteLine(message);
- player = _players[_numberPlayer];
- return true;
- }
- else
- {
- Console.WriteLine("Игрок не найден!");
- return false;
- }
- }
- else
- {
- Console.WriteLine("Игрок не найден!");
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement