Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace База_данных_игроков
- {
- class Program
- {
- static void Main(string[] args)
- {
- Players players = new Players();
- string userInput;
- bool exit = true;
- while (exit)
- {
- Console.Clear();
- Console.WriteLine("1. - Добавить игрока");
- Console.WriteLine("2. - Бан игрока");
- Console.WriteLine("3. - Разбан игрока");
- Console.WriteLine("4. - Удаление игрока");
- Console.WriteLine("5. - Показать список");
- Console.WriteLine("6. - Выход");
- Console.Write("Введите число:");
- userInput = Console.ReadLine();
- switch(userInput)
- {
- case "1":
- Console.Clear();
- Console.Write("Введите ник:");
- players.AddPlayers();
- Console.ReadKey();
- break;
- case "2":
- Console.Clear();
- Console.Write("Введите номер игрока:");
- players.BanPlayer();
- Console.ReadKey();
- break;
- case "3":
- Console.Clear();
- Console.Write("Введите номер игрока:");
- players.UnbanPlayer();
- Console.ReadKey();
- break;
- case "4":
- Console.Clear();
- Console.Write("Введите номер игрока:");
- players.DeletePlayer();
- Console.ReadKey();
- break;
- case "5":
- Console.Clear();
- players.ShowPlayer();
- Console.ReadKey();
- break;
- case "6":
- exit = false;
- break;
- }
- }
- }
- }
- class Players
- {
- private int _serialNumber;
- private string[] _nick = new string[0];
- private int [] _level = new int[0];
- private bool [] _flag = new bool[0];
- public void AddPlayers()
- {
- Random rand = new Random();
- string [] tempNick = new string[_nick.Length + 1];
- int [] tempLevel = new int[_level.Length + 1];
- bool [] tempFlag = new bool[_flag.Length + 1];
- for (int i = 0; i < _nick.Length; i++)
- {
- tempNick[i] = _nick[i];
- tempLevel[i] = _level[i];
- tempFlag[i] = _flag[i];
- }
- tempNick[tempNick.Length - 1] = Console.ReadLine();
- tempLevel[tempLevel.Length - 1] = rand.Next(0, 30);
- tempFlag[tempLevel.Length - 1] = true;
- _level = tempLevel;
- _nick = tempNick;
- _flag = tempFlag;
- }
- public void DeletePlayer()
- {
- bool personIsFinding = false;
- int index = Convert.ToInt32(Console.ReadLine());
- for (int i = 0; i < _nick.Length; i++)
- {
- if (index == (i + 1))
- {
- personIsFinding = true;
- _nick[i] = null;
- _nick = _nick.Where(x => x != null).ToArray();
- Console.WriteLine("Игрок удалён");
- }
- }
- if (personIsFinding == false)
- {
- Console.WriteLine("Такого игрока нет!");
- }
- }
- public void ShowPlayer()
- {
- _serialNumber = 0;
- for (int i = 0; i < _nick.Length; i++)
- {
- _serialNumber++;
- if(_flag[i] == true)
- {
- Console.WriteLine($"{_serialNumber}. {_nick[i]} - {_level[i]} уровень [доступ - активен]");
- }
- else if(_flag[i] == false)
- {
- Console.WriteLine($"{_serialNumber}. {_nick[i]} - {_level[i]} уровень [доступ - закрыт]");
- }
- }
- }
- public void BanPlayer()
- {
- bool playerFound = false;
- int index = Convert.ToInt32(Console.ReadLine());
- for(int j = 0; j < _nick.Length; j++)
- {
- if(index == (j + 1))
- {
- playerFound = true;
- _flag[j] = false;
- Console.WriteLine("Игрок забанен.");
- }
- }
- if(playerFound == false)
- {
- Console.WriteLine("Игрок не найден.");
- }
- }
- public void UnbanPlayer()
- {
- bool playerFound = false;
- int index = Convert.ToInt32(Console.ReadLine());
- for (int j = 0; j < _nick.Length; j++)
- {
- if (index == (j + 1))
- {
- playerFound = true;
- _flag[j] = true;
- Console.WriteLine("Игрок разбанен.");
- }
- }
- if (playerFound == false)
- {
- Console.WriteLine("Игрок не найден.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement