Nemesis_War

База данных игроков v.2

Apr 24th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.02 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 ConsoleApp9
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             bool work = true;
  14.             PlayerList playerList = new PlayerList(new BanList[]
  15.             {
  16.             new BanList(new Player("Nemesis", 23), false),
  17.             new BanList(new Player("Alex", 45), false),
  18.             new BanList(new Player("Nagibator2010", 78), false),
  19.             new BanList(new Player("Pinguin", 56), false),
  20.             new BanList(new Player("Noob", 5), false),
  21.             });
  22.  
  23.             while (work)
  24.             {
  25.                 Console.Clear();
  26.                 playerList.ShowAllPlayers();
  27.                 Console.WriteLine();
  28.                 Console.WriteLine("Вы берите действие:\nДля добавление нового игрока - нажмите 1\nДля бана игрока - нажмите 2\nДля разбана игрока - нажмите 3\nДля удаления игрока - нажмите 4\nДля выхода - нажмите 5");
  29.                 int userInput = Convert.ToInt32(Console.ReadLine());
  30.                 switch (userInput)
  31.                 {
  32.                     case 1:
  33.                         AddNewPlayer(ref playerList);
  34.                         break;
  35.                     case 2:
  36.                         CheckUserInput(ref userInput, "Бана", playerList);
  37.                         break;
  38.                     case 3:
  39.                         CheckUserInput(ref userInput, "Разбана", playerList);
  40.                         break;
  41.                     case 4:
  42.                         DelelePlayer(ref playerList);
  43.                         break;
  44.                     case 5:
  45.                         work = false;
  46.                         break;
  47.                     default:
  48.                         Console.WriteLine("Вы ввели несуществующую команду. Попробуйте еще раз.");
  49.                         break;
  50.                 }
  51.                 Console.WriteLine("Вы вышли из админской программы!");
  52.             }
  53.         }
  54.  
  55.         static void CheckUserInput(ref int userInput, string action, PlayerList playerList)
  56.         {
  57.             Console.WriteLine($"Введите номер игрока для {action}");
  58.             userInput = Convert.ToInt32(Console.ReadLine());
  59.             if (userInput <= playerList.BanLists.Length - 1)
  60.             {
  61.                 if (action == "Бана")
  62.                 {
  63.                     playerList.BanLists[userInput].Ban();
  64.                 }
  65.                 else if (action == "Разбана")
  66.                 {
  67.                     playerList.BanLists[userInput].DisBan();
  68.                 }
  69.             }
  70.             else
  71.             {
  72.                 Console.WriteLine("Вы ввели несуществующего игрока");
  73.             }
  74.         }
  75.  
  76.         static void AddNewPlayer(ref PlayerList playerList)
  77.         {
  78.             Console.Write("Введите имя нового игрока: ");
  79.             string newPlayerName = Console.ReadLine();
  80.             Console.Write("Введите уровень нового игрока: ");
  81.             int newPlayerLevel = Convert.ToInt32(Console.ReadLine());
  82.             PlayerList tempPlayerList  = new PlayerList(new BanList[playerList.BanLists.Length+1]);
  83.             for (int i = 0; i < playerList.BanLists.Length; i++)
  84.             {
  85.                 tempPlayerList.BanLists[i] = playerList.BanLists[i];
  86.             }
  87.             tempPlayerList.BanLists[tempPlayerList.BanLists.Length - 1] = new BanList(new Player(newPlayerName,newPlayerLevel),false);
  88.             playerList = tempPlayerList;
  89.         }
  90.  
  91.         static void DelelePlayer(ref PlayerList playerList)
  92.         {
  93.             Console.Write("Введите номер игрока, которого необходимо удалить: ");
  94.             int deletePlayer = Convert.ToInt32(Console.ReadLine());
  95.             PlayerList tempPlayerList = new PlayerList(new BanList[playerList.BanLists.Length - 1]);
  96.             for (int i = 0; i < tempPlayerList.BanLists.Length; i++)
  97.             {
  98.                 if (i >= deletePlayer)
  99.                 {
  100.                     tempPlayerList.BanLists[i] = playerList.BanLists[i + 1];
  101.                 }
  102.                 else
  103.                 {
  104.                     tempPlayerList.BanLists[i] = playerList.BanLists[i];
  105.                 }
  106.             }
  107.             playerList = tempPlayerList;
  108.         }
  109.     }
  110.     class Player
  111.     {
  112.         public string PlayerName { get; private set; }
  113.         public int Level { get; private set; }
  114.  
  115.         public Player(string user, int level)
  116.         {
  117.             PlayerName = user;
  118.             Level = level;
  119.         }
  120.     }
  121.  
  122.     class PlayerList
  123.     {
  124.         public BanList[] BanLists;
  125.         public PlayerList(BanList[] banLists)
  126.         {
  127.             BanLists = banLists;
  128.         }
  129.  
  130.         public void ShowAllPlayers()
  131.         {
  132.             for (int i = 0; i < BanLists.Length; i++)
  133.             {
  134.                 BanLists[i].ShowInfo(i);
  135.             }
  136.         }
  137.     }
  138.  
  139.     class BanList
  140.     {
  141.         public Player Player;
  142.         private bool _isBanned;
  143.  
  144.         public BanList(Player player, bool isBanned)
  145.         {
  146.             Player = player;
  147.             _isBanned = isBanned;
  148.         }
  149.  
  150.         public void ShowInfo(int i)
  151.         {
  152.             Console.WriteLine($"Номер игрока: {i} | Ник игрока: {Player.PlayerName} | Уровень игрока: {Player.Level} |Забанен: {_isBanned} |");
  153.         }
  154.  
  155.         public void Ban()
  156.         {
  157.             _isBanned = true;
  158.             Console.WriteLine($"Игрок - {Player.PlayerName} - ЗАБАНЕН");
  159.         }
  160.  
  161.         public void DisBan()
  162.         {
  163.             _isBanned = false;
  164.             Console.WriteLine($"Игрок - {Player.PlayerName} - Разбанен");
  165.         }
  166.     }
  167. }
Add Comment
Please, Sign In to add comment