Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Clight_24_OOP_BasePlayers
- {
- class Program
- {
- static void Main(string[] args)
- {
- int maxLenghtName = 15;
- int xSecondMenu = 55;
- ConsoleColor defaultColor = ConsoleColor.White;
- Player player1 = new Player("Rolando", 'R', ConsoleColor.Red, 69, 82);
- Player player2 = new Player("Dzubinyo", 'D', ConsoleColor.Green, 84, 68);
- Player player3 = new Player("Гушаков", '@', ConsoleColor.Blue, 71, 73);
- Player player4 = new Player("Pepe", 'Y', ConsoleColor.Magenta, 78, 76);
- Team club = new Team(new Player[] { player1, player2, player3, player4 });
- bool isActive = true;
- while (isActive)
- {
- Console.CursorVisible = false;
- Console.WriteLine("Основной состав:");
- Console.WriteLine("Номер\tИмя\t\tАватар\tВес\tРост\t\n");
- Console.SetCursorPosition(xSecondMenu, 0);
- Console.WriteLine("Скамейка запасных:");
- Console.SetCursorPosition(xSecondMenu, 1);
- Console.WriteLine("Номер\tИмя\t\tАватар\tВес\tРост\t\n");
- Console.SetCursorPosition(0, 3);
- club.ShowPlayers(defaultColor, xSecondMenu);
- Console.SetCursorPosition(0, club.NumOfPlayers() + 5);
- Console.WriteLine("Меню:");
- Console.WriteLine("F1 - Добавить игрока");
- Console.WriteLine("F2 - Удалить игрока");
- Console.WriteLine("F3 - Менеджмент состава");
- Console.WriteLine("F5 - Выход");
- ConsoleKeyInfo key = Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.F1:
- club.AddPlayer(club.NumOfPlayers(), maxLenghtName);
- break;
- case ConsoleKey.F2:
- club.DelPlayer(club.NumOfPlayers());
- break;
- case ConsoleKey.F3:
- club.ManagePlayer(club.NumOfPlayers());
- break;
- case ConsoleKey.F5:
- Console.SetCursorPosition(0, club.NumOfPlayers() + 12);
- Console.WriteLine("Играйте в футбол!");
- Console.ReadKey();
- Environment.Exit(0);
- break;
- }
- Console.Clear();
- }
- }
- }
- class Player
- {
- private string _name;
- private char _avatar;
- private ConsoleColor _color;
- private int _weigth;
- private int _speed;
- private bool _reserve;
- public Player(string name, char avatar, ConsoleColor color, int weigth, int speed, bool reserve = false)
- {
- _name = name;
- _avatar = avatar;
- _color = color;
- _weigth = weigth;
- _speed = speed;
- _reserve = reserve;
- }
- public void ShowInfo(ConsoleColor defaultColor)
- {
- if (_name.Length < 8)
- {
- CollectInfoInLine("\t\t", defaultColor);
- }
- else
- {
- CollectInfoInLine("\t", defaultColor);
- }
- }
- public void SetReservePlayer()
- {
- _reserve = true;
- }
- public void SetActivePlayer()
- {
- _reserve = false;
- }
- public bool GetStatusPlayer()
- {
- return _reserve;
- }
- private void CollectInfoInLine(string space, ConsoleColor defaultColor)
- {
- Console.Write($"{_name}{space}");
- Console.ForegroundColor = _color;
- Console.Write($"{_avatar}\t");
- Console.ForegroundColor = defaultColor;
- Console.Write($"{_weigth}\t{_speed}\n");
- }
- }
- class Team
- {
- private Player[] Club;
- public Team(Player[] club)
- {
- Club = club;
- }
- public Player[] ReservePlayers()
- {
- int numReservePlayer = 0;
- for (int i = 0; i < Club.Length; i++)
- {
- if (Club[i].GetStatusPlayer())
- {
- numReservePlayer++;
- }
- }
- int z = 0;
- int j = 0;
- Player[] reservePlayers = new Player[numReservePlayer];
- for (int i = 0; i < reservePlayers.Length; i++)
- {
- j = z;
- while (Club[j].GetStatusPlayer() != true && j < NumOfPlayers())
- {
- j++;
- }
- z = j + 1;
- reservePlayers[i] = Club[j];
- }
- return reservePlayers;
- }
- public Player[] ActivePlayers()
- {
- int numReservePlayer = 0;
- for (int i = 0; i < Club.Length; i++)
- {
- if (Club[i].GetStatusPlayer())
- {
- numReservePlayer++;
- }
- }
- int z = 0;
- int j = 0;
- Player[] activePlayers = new Player[NumOfPlayers() - numReservePlayer];
- for (int i = 0; i < activePlayers.Length; i++)
- {
- j = z;
- while (Club[j].GetStatusPlayer() && j < NumOfPlayers())
- {
- j++;
- }
- z = j + 1;
- activePlayers[i] = Club[j];
- }
- return activePlayers;
- }
- public void ShowPlayers(ConsoleColor defaultColor, int xSecondMenu)
- {
- for (int i = 0; i < ActivePlayers().Length; i++)
- {
- Console.Write($"{i + 1}\t");
- ActivePlayers()[i].ShowInfo(defaultColor);
- }
- for (int i = 0; i < ReservePlayers().Length; i++)
- {
- Console.SetCursorPosition(xSecondMenu, i + 3);
- Console.Write($"{i + 1}\t");
- ReservePlayers()[i].ShowInfo(defaultColor);
- }
- }
- public int NumOfPlayers()
- {
- return Club.Length;
- }
- public void AddPlayer(int numOfPlayer, int maxLenghtName)
- {
- string currentName = CheckInputUser("Введите имя игрока", numOfPlayer, maxLenghtName);
- char currentAvatar = CheckInputUser("Введите аватар игрока (один символ)", numOfPlayer + 1);
- ConsoleColor currentColor = CheckInputUserColor("Введите цвет аватара", numOfPlayer + 2);
- int currentWeigth = CheckInputUser("Введите вес игрока", 15, 300, numOfPlayer + 3);
- int currentSpeed = CheckInputUser("Введите скорость игрока", 1, 100, numOfPlayer + 4);
- Player currentPlayer = new Player(currentName, currentAvatar, currentColor, currentWeigth, currentSpeed);
- Player[] currentClub = new Player[Club.Length + 1];
- for (int i = 0; i < Club.Length; i++)
- {
- currentClub[i] = Club[i];
- }
- currentClub[Club.Length] = currentPlayer;
- Club = currentClub;
- }
- public void DelPlayer(int numOfPlayer)
- {
- if (ReservePlayers().Length < 1)
- {
- Console.SetCursorPosition(0, numOfPlayer + 16);
- Console.WriteLine("Игроки удаляются только со скамейки запасных\n" +
- "Чтобы поместить игрока на скамейку, нажмите - F3");
- Console.ReadKey();
- }
- else
- {
- Console.SetCursorPosition(0, numOfPlayer + 16);
- Console.WriteLine("Игрока можно удалить только со скамейки запасных");
- int currentNumPlayer = CheckInputUser("Введите номер игрока", 1, ReservePlayers().Length, numOfPlayer);
- int j = 0;
- for (int i = 0; i < Club.Length; i++)
- {
- if (Club[i].GetStatusPlayer())
- {
- j++;
- }
- if (j == currentNumPlayer)
- {
- Player[] currentClub = new Player[Club.Length - 1];
- for (int i1 = 0; i1 < i; i1++)
- {
- currentClub[i1] = Club[i1];
- }
- for (int i1 = i; i1 < currentClub.Length; i1++)
- {
- currentClub[i1] = Club[i1 + 1];
- }
- Club = currentClub;
- }
- }
- }
- }
- public void ManagePlayer(int numOfPlayer)
- {
- Console.WriteLine("\n1 - Перемещение игрока на скамейку запасных ->");
- Console.WriteLine("2 - Перемещение игрока в основной состав <-");
- int currentNumMenu = CheckInputUser("Введите номер действия", 1, 2, numOfPlayer + 3);
- int currentNumPlayer;
- int j;
- switch (currentNumMenu)
- {
- case 1:
- if (ActivePlayers().Length < 1)
- {
- Console.SetCursorPosition(0, numOfPlayer + 16);
- Console.WriteLine("Нет игроков в основном составе\n" +
- "Чтобы поместить игрока в основной состав, нажмите - F3");
- Console.ReadKey();
- }
- else
- {
- currentNumPlayer = CheckInputUser("Введите номер игрока", 1, ActivePlayers().Length, numOfPlayer + 4);
- j = 0;
- for (int i = 0; i < Club.Length; i++)
- {
- if (Club[i].GetStatusPlayer() != true)
- {
- j++;
- }
- if (j == currentNumPlayer)
- {
- Club[i].SetReservePlayer();
- break;
- }
- }
- }
- break;
- case 2:
- if (ReservePlayers().Length < 1)
- {
- Console.SetCursorPosition(0, numOfPlayer + 16);
- Console.WriteLine("Нет игроков на скамейке запасных\n" +
- "Чтобы поместить игрока на скамейку, нажмите - F3");
- Console.ReadKey();
- }
- else
- {
- currentNumPlayer = CheckInputUser("Введите номер игрока", 1, ReservePlayers().Length, numOfPlayer + 4);
- j = 0;
- for (int i = 0; i < Club.Length; i++)
- {
- if (Club[i].GetStatusPlayer())
- {
- j++;
- }
- if (j == currentNumPlayer)
- {
- Club[i].SetActivePlayer();
- break;
- }
- }
- }
- break;
- }
- }
- static int CheckInputUser(string text, int minValue, int maxValue, int numOfPlayer)
- {
- bool goodCheckInput;
- bool isCheckInput = true;
- int input = 1;
- Console.CursorVisible = true;
- while (isCheckInput)
- {
- Console.SetCursorPosition(0, numOfPlayer + 11);
- Console.Write($"{text} от {minValue} до {maxValue}: ");
- string userInput = Console.ReadLine();
- goodCheckInput = Int32.TryParse(userInput, out int value);
- if (goodCheckInput != true || value < minValue || value > maxValue)
- {
- Console.WriteLine("Введите корректное число.");
- Console.ReadKey();
- Console.SetCursorPosition(0, numOfPlayer + 11);
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- }
- else
- {
- input = value;
- isCheckInput = false;
- Console.SetCursorPosition(0, numOfPlayer + 12);
- Console.WriteLine(" ");
- }
- }
- return input;
- }
- static int CheckInputUser(string text, Player[] club, int numOfPlayer)
- {
- bool goodCheckInput;
- bool isCheckInput = true;
- int input = 1;
- Console.CursorVisible = true;
- while (isCheckInput)
- {
- Console.SetCursorPosition(0, numOfPlayer + 11);
- Console.Write($"{text}: ");
- string userInput = Console.ReadLine();
- goodCheckInput = Int32.TryParse(userInput, out int value);
- if (goodCheckInput != true || value < 0 || value > club.Length)
- {
- Console.WriteLine("Введите корректное число.");
- Console.ReadKey();
- Console.SetCursorPosition(0, numOfPlayer + 11);
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- }
- else
- {
- input = value;
- isCheckInput = false;
- Console.SetCursorPosition(0, numOfPlayer + 12);
- Console.WriteLine(" ");
- }
- }
- return input;
- }
- static string CheckInputUser(string text, int numOfPlayer, int maxLenghtName)
- {
- bool isCheckInput = true;
- string input = "х";
- Console.CursorVisible = true;
- while (isCheckInput)
- {
- Console.SetCursorPosition(0, numOfPlayer + 11);
- Console.Write($"{text}: ");
- string userInput = Console.ReadLine();
- if (userInput.Length <= maxLenghtName && userInput.Length > 0)
- {
- input = userInput;
- isCheckInput = false;
- }
- else
- {
- Console.WriteLine($"Введите имя не более {maxLenghtName} символов");
- Console.ReadKey();
- Console.SetCursorPosition(0, numOfPlayer + 11);
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- }
- }
- return input;
- }
- static char CheckInputUser(string text, int numOfPlayer)
- {
- bool isCheckInput = true;
- char input = ' ';
- Console.CursorVisible = true;
- while (isCheckInput)
- {
- Console.SetCursorPosition(0, numOfPlayer + 11);
- Console.Write($"{text}: ");
- string userInput = Console.ReadLine();
- if (userInput.Length == 1)
- {
- input = Convert.ToChar(userInput);
- isCheckInput = false;
- }
- else
- {
- Console.WriteLine($"Введите один символ");
- Console.ReadKey();
- Console.SetCursorPosition(0, numOfPlayer + 11);
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- }
- }
- return input;
- }
- static ConsoleColor CheckInputUserColor(string text, int numOfPlayer)
- {
- bool isCheckInput = true;
- ConsoleColor input = ConsoleColor.White;
- Console.CursorVisible = true;
- while (isCheckInput)
- {
- Console.SetCursorPosition(0, numOfPlayer + 16);
- Console.WriteLine("Варианты цветов: White, Red, Blue, Green, Gray, Cyan, Magenta, Yellow\n" +
- "Также, вы можете добавить приставку Dark (кроме White). Например, DarkRed.");
- Console.SetCursorPosition(0, numOfPlayer + 11);
- Console.Write($"{text}: ");
- string userInput = Console.ReadLine().ToLower();
- switch (userInput)
- {
- case "white": input = ConsoleColor.White; isCheckInput = false; break;
- case "red": input = ConsoleColor.Red; isCheckInput = false; break;
- case "blue": input = ConsoleColor.Blue; isCheckInput = false; break;
- case "green": input = ConsoleColor.Green; isCheckInput = false; break;
- case "gray": input = ConsoleColor.Gray; isCheckInput = false; break;
- case "cyan": input = ConsoleColor.Cyan; isCheckInput = false; break;
- case "magenta": input = ConsoleColor.Magenta; isCheckInput = false; break;
- case "yellow": input = ConsoleColor.Yellow; isCheckInput = false; break;
- case "darkred": input = ConsoleColor.DarkRed; isCheckInput = false; break;
- case "darkblue": input = ConsoleColor.DarkBlue; isCheckInput = false; break;
- case "darkgreen": input = ConsoleColor.DarkGreen; isCheckInput = false; break;
- case "darkgray": input = ConsoleColor.DarkGray; isCheckInput = false; break;
- case "darkcyan": input = ConsoleColor.DarkCyan; isCheckInput = false; break;
- case "darkmagenta": input = ConsoleColor.DarkMagenta; isCheckInput = false; break;
- case "darkyellow": input = ConsoleColor.DarkYellow; isCheckInput = false; break;
- default:
- Console.WriteLine("Вы ввели не корректный цвет");
- Console.ReadKey();
- Console.SetCursorPosition(0, numOfPlayer + 11);
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- break;
- }
- Console.SetCursorPosition(0, numOfPlayer + 16);
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- }
- return input;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement