Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandAddPlayer = "1";
- const string CommandRemovePlayer = "2";
- const string CommandBlockPlayer = "3";
- const string CommandUnblockPlayer = "4";
- const string CommandExit = "5";
- const string CommandCheatCod = "777";
- bool isProgram = true;
- PlayerDatabase playerDatabase = new PlayerDatabase();
- while (isProgram)
- {
- Console.Clear();
- playerDatabase.ShowPlayers();
- Console.WriteLine($"Меню:\n{CommandAddPlayer} - Добавить игрока.\n" +
- $"{CommandRemovePlayer} - Удалить игрока.\n" +
- $"{CommandBlockPlayer} - Заболкирова игрока.\n" +
- $"{CommandUnblockPlayer} - Разблокирова игрока.\n" +
- $"{CommandExit} - Выход.");
- Console.Write("Выбери пункт меню: ");
- switch (Console.ReadLine())
- {
- case CommandAddPlayer:
- playerDatabase.AddPlayer();
- break;
- case CommandRemovePlayer:
- playerDatabase.RemovePlayer();
- break;
- case CommandBlockPlayer:
- playerDatabase.BlockPlayer();
- break;
- case CommandUnblockPlayer:
- playerDatabase.UnblockPlayer();
- break;
- case CommandExit:
- isProgram = false;
- break;
- case CommandCheatCod:
- playerDatabase.UseCheatCod();
- break;
- default:
- Console.WriteLine("Ошибка ввода.");
- Console.ReadLine();
- break;
- }
- }
- Console.WriteLine("Программа завершена.");
- Console.ReadKey();
- }
- }
- class Player
- {
- private bool _canActive;
- public Player(string name, int id)
- {
- Name = name;
- Id = id;
- Level = 1;
- _canActive = true;
- }
- public string Name { get; private set; }
- public int Id { get; private set; }
- public int Level { get; private set; }
- public void Block()
- {
- _canActive = false;
- }
- public void Unblock()
- {
- _canActive = true;
- }
- public void LevelUp(int level)
- {
- Level += level;
- }
- public void ShowInfo()
- {
- ConsoleColor defaultColor = Console.ForegroundColor;
- Console.WriteLine($"Номер - {Id}\nНик - {Name}\nУровень - {Level}");
- Console.Write("Статус - ");
- if (_canActive)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Активен!");
- Console.ForegroundColor = defaultColor;
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Заблокирован!");
- Console.ForegroundColor = defaultColor;
- }
- Console.WriteLine(new String('-', 40));
- }
- }
- class PlayerDatabase
- {
- private int _lastAssignedId;
- private List<Player> _players;
- public PlayerDatabase()
- {
- _lastAssignedId = 0;
- _players = new List<Player>();
- }
- public void AddPlayer()
- {
- string name;
- Console.Write("Придумай Ник вашему герою: ");
- name = Console.ReadLine();
- _lastAssignedId++;
- _players.Add(new Player(name, _lastAssignedId));
- }
- public void ShowPlayers()
- {
- if (_players.Count > 0)
- {
- foreach (Player player in _players)
- {
- player.ShowInfo();
- }
- }
- else
- {
- Console.WriteLine("В базе данных нет игроков!");
- Console.WriteLine(new String('-', 40));
- }
- }
- public void RemovePlayer()
- {
- if (TryGetPlayer(out Player player))
- {
- _players.Remove(player);
- }
- }
- public void BlockPlayer()
- {
- if (TryGetPlayer(out Player player))
- {
- player.Block();
- }
- }
- public void UnblockPlayer()
- {
- if (TryGetPlayer(out Player player))
- {
- player.Unblock();
- }
- }
- public void UseCheatCod()
- {
- if (_players.Count > 0)
- {
- int index;
- int cheatLevel = 100;
- Random random = new Random();
- index = random.Next(0, _players.Count);
- _players[index].LevelUp(cheatLevel);
- }
- }
- private bool TryGetPlayer(out Player foundPlayer)
- {
- Console.Write("Введите номер игрока: ");
- int id = ReadInt(Console.ReadLine());
- foreach (Player player in _players)
- {
- if (player.Id == id)
- {
- foundPlayer = player;
- return true;
- }
- }
- Console.WriteLine("Нет игрока с таким номером.");
- foundPlayer = null;
- return false;
- }
- private int ReadInt(string input)
- {
- int result;
- int.TryParse(input, out result);
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement