Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace LinqTask4PlayersTop
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- GameServer gameServer = new GameServer();
- gameServer.ShowTopPlayers(3);
- }
- }
- public class GameServer
- {
- private List<Player> _players = new List<Player>();
- public GameServer()
- {
- FillPlayers();
- }
- public void ShowTopPlayers(int topPlayersCount)
- {
- Console.WriteLine("Весь список:");
- ShowPlayers(_players);
- List<Player> playersTopByLevel = _players.OrderByDescending(player => player.Level).Take(topPlayersCount).ToList();
- Console.WriteLine($"\nТоп {topPlayersCount} по уровню:");
- ShowPlayers(playersTopByLevel);
- List<Player> playersTopByPower = _players.OrderByDescending(player => player.Power).Take(topPlayersCount).ToList();
- Console.WriteLine($"\nТоп {topPlayersCount} по силе:");
- ShowPlayers(playersTopByPower);
- }
- private void ShowPlayers(List<Player> players)
- {
- foreach (var player in players)
- {
- player.ShowInfo();
- }
- }
- private void FillPlayers()
- {
- const int MinimumLevel = 1;
- const int MaximumLevel = 100;
- const int MinimumPower = 1;
- const int MaximumPower = 1000;
- string[] names = {
- "Вася",
- "Петя",
- "Леша",
- "Дима",
- "Айгуль",
- "Люся",
- "Паша",
- "Вера",
- "Зина",
- "Ася",
- "Нина",
- "Рома",
- "Саша",
- };
- Random random = new Random();
- foreach (string name in names)
- {
- _players.Add(new Player(name, random.Next(MinimumLevel, MaximumLevel),
- random.Next(MinimumPower, MaximumPower)));
- }
- }
- }
- public class Player
- {
- private string _name;
- public Player(string name, int level, int power)
- {
- _name = name;
- Level = level;
- Power = power;
- }
- public int Level { get; private set; }
- public int Power { get; private set; }
- public void ShowInfo()
- {
- Console.WriteLine($"{_name}, уровень: {Level}, сила: {Power}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement