Advertisement
VoVfe

Untitled

Jun 14th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace База_данных_игроков
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Players players = new Players();
  14.             string userInput;
  15.             bool exit = true;
  16.  
  17.             while (exit)
  18.             {
  19.                Console.Clear();
  20.                Console.WriteLine("1. - Добавить игрока");
  21.                Console.WriteLine("2. - Бан игрока");
  22.                Console.WriteLine("3. - Разбан игрока");
  23.                Console.WriteLine("4. - Удаление игрока");
  24.                Console.WriteLine("5. - Показать список");
  25.                Console.WriteLine("6. - Выход");
  26.                Console.Write("Введите число:");
  27.                userInput = Console.ReadLine();
  28.  
  29.                switch(userInput)
  30.                {
  31.                     case "1":
  32.                         Console.Clear();
  33.                         Console.Write("Введите ник:");
  34.                         players.AddPlayers();
  35.                         Console.ReadKey();
  36.                         break;
  37.                     case "2":
  38.                         Console.Clear();
  39.                         Console.Write("Введите номер игрока:");
  40.                         players.BanPlayer();
  41.                         Console.ReadKey();
  42.                         break;
  43.                     case "3":
  44.                         Console.Clear();
  45.                         Console.Write("Введите номер игрока:");
  46.                         players.UnbanPlayer();
  47.                         Console.ReadKey();
  48.                         break;
  49.                     case "4":
  50.                         Console.Clear();
  51.                         Console.Write("Введите номер игрока:");
  52.                         players.DeletePlayer();
  53.                         Console.ReadKey();
  54.                         break;
  55.                     case "5":
  56.                         Console.Clear();
  57.                         players.ShowPlayer();
  58.                         Console.ReadKey();
  59.                         break;
  60.                     case "6":
  61.                         exit = false;
  62.                         break;
  63.                 }
  64.             }
  65.         }
  66.     }
  67.  
  68.     class Players
  69.     {
  70.         private int _serialNumber;
  71.         private string[] _nick = new string[0];
  72.         private int [] _level = new int[0];
  73.         private bool [] _flag = new bool[0];
  74.  
  75.         public void AddPlayers()
  76.         {
  77.             Random rand = new Random();
  78.             string [] tempNick = new string[_nick.Length + 1];
  79.             int [] tempLevel = new int[_level.Length + 1];
  80.             bool [] tempFlag = new bool[_flag.Length + 1];
  81.  
  82.             for (int i = 0; i < _nick.Length; i++)
  83.             {
  84.                 tempNick[i] = _nick[i];
  85.                 tempLevel[i] = _level[i];
  86.                 tempFlag[i] = _flag[i];
  87.             }
  88.  
  89.             tempNick[tempNick.Length - 1] = Console.ReadLine();
  90.             tempLevel[tempLevel.Length - 1] = rand.Next(0, 30);
  91.             tempFlag[tempLevel.Length - 1] = true;
  92.             _level = tempLevel;
  93.             _nick = tempNick;
  94.             _flag = tempFlag;
  95.         }
  96.        
  97.         public void DeletePlayer()
  98.         {
  99.             bool personIsFinding = false;
  100.             int index = Convert.ToInt32(Console.ReadLine());
  101.             for (int i = 0; i < _nick.Length; i++)
  102.             {
  103.                 if (index == (i + 1))
  104.                 {
  105.                     personIsFinding = true;
  106.                     _nick[i] = null;
  107.                     _nick = _nick.Where(x => x != null).ToArray();
  108.                     Console.WriteLine("Игрок удалён");
  109.                 }
  110.             }
  111.  
  112.             if (personIsFinding == false)
  113.             {
  114.                 Console.WriteLine("Такого игрока нет!");
  115.             }
  116.         }
  117.  
  118.         public void ShowPlayer()
  119.         {
  120.             _serialNumber = 0;
  121.  
  122.             for (int i = 0; i < _nick.Length; i++)
  123.             {
  124.                 _serialNumber++;
  125.               if(_flag[i] == true)
  126.               {
  127.                 Console.WriteLine($"{_serialNumber}. {_nick[i]} - {_level[i]} уровень [доступ - активен]");
  128.               }
  129.  
  130.               else if(_flag[i] == false)
  131.               {
  132.                 Console.WriteLine($"{_serialNumber}. {_nick[i]} - {_level[i]} уровень [доступ - закрыт]");
  133.               }
  134.             }
  135.         }
  136.  
  137.         public void BanPlayer()
  138.         {
  139.             bool playerFound = false;
  140.             int index = Convert.ToInt32(Console.ReadLine());
  141.  
  142.             for(int j = 0; j < _nick.Length; j++)
  143.             {
  144.                 if(index == (j + 1))
  145.                 {
  146.                     playerFound = true;
  147.                     _flag[j] = false;
  148.                     Console.WriteLine("Игрок забанен.");
  149.                 }
  150.             }
  151.  
  152.             if(playerFound == false)
  153.             {
  154.                 Console.WriteLine("Игрок не найден.");
  155.             }
  156.         }
  157.  
  158.         public void UnbanPlayer()
  159.         {
  160.             bool playerFound = false;
  161.             int index = Convert.ToInt32(Console.ReadLine());
  162.  
  163.             for (int j = 0; j < _nick.Length; j++)
  164.             {
  165.                 if (index == (j + 1))
  166.                 {
  167.                     playerFound = true;
  168.                     _flag[j] = true;
  169.                     Console.WriteLine("Игрок разбанен.");
  170.                 }
  171.             }
  172.  
  173.             if (playerFound == false)
  174.             {
  175.                 Console.WriteLine("Игрок не найден.");
  176.             }
  177.         }
  178.     }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement