Advertisement
VodVas

Топ игроков сервера

Jan 15th, 2024 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.69 KB | Software | 0 0
  1. using System.Linq;
  2.  
  3. namespace Топ_игроков_сервера
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Server server = new Server();
  10.  
  11.             server.Work();
  12.         }
  13.     }
  14.     class Server
  15.     {
  16.         private List<Player> _players = new List<Player>();
  17.  
  18.         private int _quantityTopPlayers = 3;
  19.  
  20.         public Server()
  21.         {
  22.             _players.Add(new Player("electroNic", 93, 2200));
  23.             _players.Add(new Player("device", 88, 2430));
  24.             _players.Add(new Player("Magisk", 99, 2300));
  25.             _players.Add(new Player("dupreeh", 70, 2500));
  26.             _players.Add(new Player("Xyp9x", 63, 2450));
  27.             _players.Add(new Player("gla1ve", 94, 2400));
  28.             _players.Add(new Player("FalleN", 87, 2100));
  29.             _players.Add(new Player("karrigan", 85, 2170));
  30.             _players.Add(new Player("s1mple", 77, 2320));
  31.             _players.Add(new Player("TACO", 90, 2150));
  32.         }
  33.  
  34.         public void Work()
  35.         {
  36.             Console.WriteLine("Игроки на сервере:");
  37.  
  38.             ShowPlayersList(_players);
  39.  
  40.             Console.WriteLine($"\nТоп {_quantityTopPlayers} игроков по уровню:");
  41.  
  42.             ShowLevelTop();
  43.  
  44.             Console.WriteLine($"\nТоп {_quantityTopPlayers} игроков по силе:");
  45.  
  46.             ShowPowerTop();
  47.         }
  48.  
  49.         private void ShowPowerTop()
  50.         {
  51.             List<Player> topPowerPlayers = new List<Player>();
  52.  
  53.             topPowerPlayers = _players.OrderByDescending(player => player.Power).Take(_quantityTopPlayers).ToList();
  54.  
  55.             ShowPlayersList(topPowerPlayers);
  56.         }
  57.  
  58.         private void ShowLevelTop()
  59.         {
  60.             List<Player> topLevelPlayers = new List<Player>();
  61.  
  62.             topLevelPlayers = _players.OrderByDescending(player => player.Level).Take(_quantityTopPlayers).ToList();
  63.  
  64.             ShowPlayersList(topLevelPlayers);
  65.         }
  66.  
  67.         private void ShowPlayersList(List<Player> players)
  68.         {
  69.             foreach (var player in players)
  70.             {
  71.                 player.ShowDescription();
  72.             }
  73.         }
  74.     }
  75.  
  76.     class Player
  77.     {
  78.         public Player(string name, int level, int power)
  79.         {
  80.             Name = name;
  81.             Level = level;
  82.             Power = power;
  83.         }
  84.  
  85.         public string Name { get; private set; }
  86.         public int Level { get; private set; }
  87.         public int Power { get; private set; }
  88.  
  89.         public void ShowDescription()
  90.         {
  91.             Console.WriteLine($"Имя: {Name} Уровень: {Level} Power: {Power}");
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement