Advertisement
Rodunskiy

Untitled

Jul 17th, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.81 KB | None | 0 0
  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {  
  5.         DataBase dataBase = new DataBase();
  6.         string userInput;
  7.         bool isWorking = true;
  8.  
  9.         while (isWorking)
  10.         {
  11.             Console.Clear();
  12.             Console.WriteLine("Выберите действие:\n1)Добавить игрока.\n2)Забанить игрока.\n3)Разбанить игрока.\n4)Удалить игрока.\n5)Выход из программы.");
  13.             userInput = Console.ReadLine();
  14.  
  15.             switch (userInput)
  16.             {
  17.                 case "1":
  18.                     dataBase.AddPlayer();
  19.                     break;
  20.  
  21.                 case "2":
  22.                     dataBase.BanPlayer();
  23.                     break;
  24.  
  25.                 case "3":
  26.                     dataBase.UnbanPlayer();
  27.                     break;
  28.  
  29.                 case "4":
  30.                     dataBase.DeletePlayer();
  31.                     break;
  32.  
  33.                 case "5":
  34.                     isWorking = false;
  35.                     break;
  36.             }
  37.         }
  38.     }
  39. }
  40.  
  41. class Player
  42. {
  43.     public int Number { get; private set; }
  44.     public string Nickname { get; private set; }
  45.     public int LVL { get; private set; }
  46.     public bool Flag;
  47.     public Player(int number, string nickname, int lvl, bool flag)
  48.     {
  49.         Number = number;
  50.         Nickname = nickname;
  51.         LVL = lvl;
  52.         Flag = flag;
  53.     }
  54. }
  55.  
  56. class DataBase
  57. {
  58.     private List<Player> _players = new List<Player>();
  59.     private int _universalNumber = 1000;
  60.  
  61.     public void ShowTablePlayers()
  62.     {
  63.         for (int i = 0; i < _players.Count; i++)
  64.         {
  65.             if (_players[i].Flag == true)
  66.             {
  67.                 Console.ForegroundColor = ConsoleColor.Green;
  68.                 Console.WriteLine($"Уникальный номер:{_players[i].Number}|Никнейм:{_players[i].Nickname}|LVL:{_players[i].LVL}");
  69.                 Console.ForegroundColor = ConsoleColor.White;
  70.             }
  71.             else
  72.             {
  73.                 Console.ForegroundColor = ConsoleColor.Red;
  74.                 Console.WriteLine($"Уникальный номер:{_players[i].Number}|Никнейм:{_players[i].Nickname}|LVL:{_players[i].LVL}");
  75.                 Console.ForegroundColor = ConsoleColor.White;
  76.             }
  77.         }
  78.     }
  79.  
  80.     public void DeletePlayer()
  81.     {
  82.         int userInput;
  83.         Console.WriteLine("Игрока под каким уникальным номером вы хотите удалить?");
  84.  
  85.         ShowTablePlayers();
  86.  
  87.         userInput = Convert.ToInt32(Console.ReadLine());
  88.  
  89.         _players.RemoveAt(userInput - 1000);
  90.     }
  91.  
  92.     public void UnbanPlayer()
  93.     {
  94.         int userInput;
  95.         Console.WriteLine("Игрока под каким уникальным номером вы хотите разбанить?");
  96.  
  97.         ShowTablePlayers();
  98.  
  99.         userInput = Convert.ToInt32(Console.ReadLine());
  100.  
  101.         _players[userInput - 1000].Flag = true;
  102.  
  103.         Console.ReadKey();
  104.     }
  105.     public void BanPlayer()
  106.     {
  107.         int userInput;
  108.         Console.WriteLine("Игрока под каким уникальным номером вы хотите забанить?");
  109.  
  110.         ShowTablePlayers();
  111.  
  112.         userInput = Convert.ToInt32(Console.ReadLine());
  113.  
  114.         _players[userInput - 1000].Flag = false;
  115.  
  116.         Console.ReadKey();
  117.     }
  118.  
  119.     public void AddPlayer()
  120.     {
  121.         string userInputName;
  122.         int userInputLvl;
  123.  
  124.         Console.WriteLine("Введите ник игрока и его LVL");
  125.         userInputName = Console.ReadLine();
  126.         userInputLvl = Convert.ToInt32(Console.ReadLine());
  127.  
  128.         _players.Add(new Player(_universalNumber, userInputName, userInputLvl, true));
  129.  
  130.         _universalNumber++;
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement