Advertisement
LeRoY_Go

Untitled

Feb 9th, 2022
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace C_Sharp_Junior
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             BasePlayers basePlayers = new BasePlayers(new List<Player> { new Player("Эмма", 5, false), new Player("Луис", 1, false) });
  11.  
  12.             while (true)
  13.             {
  14.                 Console.Write("1 - Добавить игрока\n2 - Бан игрока\n3 - Разбан игрока\n4 - Удалить игрока\n5 - Показать базу игроков\n Введите команду: ");
  15.                 string userInput = Console.ReadLine();
  16.  
  17.                 switch (userInput)
  18.                 {
  19.                     case "1":
  20.                         basePlayers.AddPlayer();
  21.                         break;
  22.                     case "2":
  23.                         basePlayers.BanPlayer();
  24.                         break;
  25.                     case "3":
  26.                         basePlayers.UnbanPlayer();
  27.                         break;
  28.                     case "4":
  29.                         basePlayers.DeletePlayer();
  30.                         break;
  31.                     case "5":
  32.                         basePlayers.DrawPlayerInfo();
  33.                         break;
  34.                 }
  35.  
  36.                 Console.Write("Нажмите кнопку для возврата в меню");
  37.                 Console.ReadLine();
  38.                 Console.Clear();
  39.             }
  40.         }
  41.     }
  42.  
  43.     class Player
  44.     {
  45.         public string NickName { get; private set; }
  46.         public int Level { get; private set; }
  47.         public bool BanStatus { get; private set; }
  48.  
  49.         public Player(string nickName, int level, bool banStatus)
  50.         {
  51.             NickName = nickName;
  52.             Level = level;
  53.             BanStatus = banStatus;
  54.         }
  55.  
  56.         public void Ban()
  57.         {
  58.             BanStatus = true;
  59.         }
  60.  
  61.         public void Unban()
  62.         {
  63.             BanStatus = false;
  64.         }
  65.     }
  66.  
  67.     class BasePlayers
  68.     {
  69.         private List<Player> _players = new List<Player>();
  70.  
  71.         public BasePlayers(List<Player> players)
  72.         {
  73.             _players = players;
  74.         }
  75.  
  76.         public void AddPlayer()
  77.         {
  78.             Console.Write("Введите ник: ");
  79.             string nickName = Console.ReadLine();
  80.             Console.Write("Введите уровень: ");
  81.             int level = Convert.ToInt32(Console.ReadLine());
  82.             _players.Add(new Player(nickName, level, false));
  83.         }
  84.  
  85.         public void BanPlayer()
  86.         {
  87.             Console.Write("Введите номер игрока: ");
  88.             int input = Convert.ToInt32(Console.ReadLine()) - 1;
  89.  
  90.             if (input <= _players.Count && input > 0)
  91.             {
  92.                 _players[input].Ban();
  93.             }
  94.             else
  95.             {
  96.                 Console.WriteLine("Игрок с данным номером отсутствует");
  97.             }
  98.         }
  99.  
  100.         public void UnbanPlayer()
  101.         {
  102.             Console.Write("Введите номер игрока: ");
  103.             int input = Convert.ToInt32(Console.ReadLine()) - 1;
  104.  
  105.             if (input <= _players.Count && input > 0)
  106.             {
  107.                 _players[input].Unban();
  108.             }
  109.             else
  110.             {
  111.                 Console.WriteLine("Игрок с данным номером отсутствует");
  112.             }
  113.         }
  114.  
  115.         public void DeletePlayer()
  116.         {
  117.             Console.Write("Введите номер игрока: ");
  118.             int input = Convert.ToInt32(Console.ReadLine()) - 1;
  119.  
  120.             if (input <= _players.Count && input > 0)
  121.             {
  122.                 _players.RemoveAt(input);
  123.             }
  124.             else
  125.             {
  126.                 Console.WriteLine("Игрок с данным номером отсутствует");
  127.             }
  128.         }
  129.  
  130.         public void DrawPlayerInfo()
  131.         {
  132.             for (int i = 0; i < _players.Count; i++)
  133.             {
  134.                 Console.WriteLine("Номер: " + (i + 1) + " | Ник: " + _players[i].NickName + " | Уровень: " + _players[i].Level + " | Статус бан: " + _players[i].BanStatus);
  135.             }
  136.         }
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement