Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- internal class Program
- {
- // У нас есть список всех игроков(минимум 10). У каждого игрока есть поля: имя, уровень, сила.
- // Требуется написать запрос для определения топ 3 игроков по уровню и топ 3 игроков по силе, после чего вывести каждый топ.
- // 2 запроса получится.
- static void Main(string[] args)
- {
- Database database = new Database();
- database.RunProgram();
- }
- class Player
- {
- public string Name { get; }
- public int Level { get; }
- public int Power { get; }
- public Player(string name, int level, int power)
- {
- Name = name;
- Level = level;
- Power = power;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Имя: {Name} Уровень: {Level} Сила: {Power}");
- }
- }
- class Database
- {
- private List<Player> _players;
- public Database()
- {
- _players = new List<Player>();
- Fill();
- }
- public void RunProgram()
- {
- string CommandPointOne = "1";
- string CommandPointTwo = "2";
- bool inProgram = true;
- while (inProgram)
- {
- Console.WriteLine("Список игроков сервера.\n");
- ShowInfo();
- Console.Write($"\nМеню:\n{CommandPointOne}. Показать ТОП игроков по Уровню." +
- $"\n{CommandPointTwo}. Показать ТОП игроков по Силе.\nДля выхода нажми любую клавишу.\nВаш выбор: ");
- string userInput = Console.ReadLine();
- if (userInput == CommandPointOne)
- {
- ShowTopLevel();
- }
- else if (userInput == CommandPointTwo)
- {
- ShowTopPower();
- }
- else
- {
- Console.WriteLine("Программа завершена.");
- inProgram = false;
- Console.ReadKey();
- }
- Console.ReadKey();
- Console.Clear();
- }
- }
- private void ShowInfo()
- {
- foreach (var player in _players)
- {
- player.ShowInfo();
- }
- }
- private void ShowTopLevel()
- {
- int countTopPlayers = 3;
- var filterPlayers = _players.OrderByDescending(player => player.Level).Take(countTopPlayers);
- ShowFilterLinq(filterPlayers);
- }
- private void ShowTopPower()
- {
- int countTopPlayers = 3;
- var filterPlayers = _players.OrderByDescending(player => player.Power).Take(countTopPlayers);
- ShowFilterLinq(filterPlayers);
- }
- private void ShowFilterLinq(IEnumerable<Player> filterPlayers)
- {
- foreach (var patient in filterPlayers)
- {
- patient.ShowInfo();
- }
- }
- private void Fill()
- {
- Player[] player =
- {
- new Player("Lol", 40, 450),
- new Player("Smit", 5, 200),
- new Player("Knyzi", 15, 400),
- new Player("Sutiner", 6, 180),
- new Player("Nagibator666", 80, 1100),
- new Player("Kek", 66, 630),
- new Player("Agranom", 54, 680),
- new Player("Master", 5, 110),
- new Player("Bob777", 28, 310),
- new Player("Player", 37, 410),
- new Player("Golum", 6, 220),
- new Player("Zadira", 10, 380),
- new Player("Batya", 4, 140)
- };
- _players.AddRange(player);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement