Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace IMJunior
- {
- class Program
- {
- static void Main(string[] args)
- {
- Player[] player = new Player[0];
- bool isPlaying = true;
- DataBase database = new DataBase(player);
- while (isPlaying)
- {
- Console.Clear();
- DrawMenu();
- int chose = Convert.ToInt32(Console.ReadLine());
- if (chose == 1)
- {
- Console.Clear();
- Console.Write("Введите имя: ");
- string name = Console.ReadLine();
- Console.Write("Введите уровень: ");
- int level = Convert.ToInt32(Console.ReadLine());
- database.AddPlayer(name, level);
- }
- else if (chose == 2)
- {
- Console.Clear();
- database.AllPlayersInfo();
- Console.SetCursorPosition(50, 0);
- Console.Write("Какого игрока удалить: ");
- int number = Convert.ToInt32(Console.ReadLine());
- database.DeletePlayer(number);
- }
- else if (chose == 3)
- {
- database.AllPlayersInfo();
- Console.SetCursorPosition(50, 0);
- Console.Write("Какого игрока забанить: ");
- int chose2 = Convert.ToInt32(Console.ReadLine());
- if (chose2 - 1 >= 0 && chose2 - 1 <= player.Length)
- {
- database.BanAndUnban(true, "Игрок уже забанен!", chose2);
- }
- else
- {
- Console.Clear();
- Console.WriteLine("Неверный ввод!");
- Console.ReadLine();
- }
- }
- else if (chose == 4)
- {
- database.AllPlayersInfo();
- Console.SetCursorPosition(50, 0);
- Console.Write("Какого игрока разбанить: ");
- int chose2 = Convert.ToInt32(Console.ReadLine());
- if (chose2 - 1 >= 0 && chose2 - 1 <= player.Length)
- {
- database.BanAndUnban(false, "Игрок уже разбанен!", chose2);
- }
- else
- {
- Console.Clear();
- Console.WriteLine("Неверный ввод!");
- Console.ReadLine();
- }
- }
- else if (chose == 5)
- {
- database.AllPlayersInfo();
- Console.ReadLine();
- }
- else Console.WriteLine("Неверный ввод!");
- }
- }
- static void DrawMenu()
- {
- Console.WriteLine("1) Добавить игрока");
- Console.WriteLine("2) Удалить игрока");
- Console.WriteLine("3) Забанить игрока");
- Console.WriteLine("4) Разбанить игрока");
- Console.WriteLine("5) Вывод игроков");
- Console.Write("Выбрать пункт: ");
- }
- }
- class DataBase
- {
- public Player[] Players;
- public DataBase(Player[] players)
- {
- Players = players;
- }
- public void AllPlayersInfo()
- {
- Console.Clear();
- for (int i = 0; i < Players.Length; i++)
- {
- Console.WriteLine($"Номер игрока: {Players[i].Number} \nИмя игорка: {Players[i].Name}\nУровень игрока: {Players[i].Level}\nФлаг: {Players[i].Flag}");
- Console.WriteLine();
- }
- }
- public void AddPlayer(string name, int level)
- {
- Player[] tempPlayer = new Player[Players.Length + 1];
- tempPlayer[tempPlayer.Length - 1] = new Player(tempPlayer.Length, name, level, true);
- for (int i = 0; i < Players.Length; i++)
- {
- tempPlayer[i] = Players[i];
- }
- Players = tempPlayer;
- }
- public void DeletePlayer(int number)
- {
- Player[] tempPlayer = new Player[Players.Length - 1];
- Player[] copyPlayer = new Player[Players.Length];
- copyPlayer = Players;
- int tempNumber = copyPlayer[number - 1].Number;
- copyPlayer[number - 1] = copyPlayer[copyPlayer.Length - 1];
- copyPlayer[number - 1].Number = tempNumber;
- for (int i = 0; i < copyPlayer.Length; i++)
- {
- if (i < copyPlayer.Length - 1)
- {
- tempPlayer[i] = copyPlayer[i];
- }
- }
- Players = tempPlayer;
- }
- public void BanAndUnban(bool flag, string message, int chose)
- {
- if (Players[chose - 1].Flag == flag)
- Players[chose - 1].Flag = !flag;
- else
- {
- Console.Clear();
- Console.WriteLine(message);
- Console.ReadLine();
- }
- }
- }
- class Player
- {
- public int Number;
- private string _name;
- private int _level;
- public bool Flag;
- public string Name { get { return _name; } set { _name = value ; } }
- public int Level { get { return _level; } set { _level = value; } }
- public Player(int number, string name, int level, bool flag)
- {
- Number = number;
- _name = name;
- _level = level;
- Flag = flag;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement