Created
May 29, 2024 18:20
-
-
Save EreminAndrei/6ff1d2f9728c72454cdd4801560fadf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Project3 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
PlayersDatabase playersDatabase = new PlayersDatabase(); | |
playersDatabase.Work(); | |
} | |
class UserUtils | |
{ | |
private static Random s_random = new Random(); | |
public static int GenerateRandomNumber(int min, int max) | |
{ | |
return s_random.Next(min, max); | |
} | |
} | |
class PlayersDatabase | |
{ | |
private List<Player> _players; | |
public PlayersDatabase() | |
{ | |
int maxNumberOfPlayers = 25; | |
int minLevel = 0; | |
int maxLevel = 100; | |
int minStrength = 1; | |
int maxStrength = 200; | |
List<Player> players = new List<Player>(); | |
string[] names = new string[] { "Билл", "Джон", "Джек", "Кларк", "Питер", "Виктор", "Дик", "Майкл" }; | |
for (int i = 0; i < maxNumberOfPlayers; i++) | |
{ | |
players.Add(new Player(names[UserUtils.GenerateRandomNumber(0, names.Length)], UserUtils.GenerateRandomNumber(minLevel, maxLevel), | |
UserUtils.GenerateRandomNumber(minStrength, maxStrength))); | |
} | |
_players = players; | |
} | |
public void Work() | |
{ | |
Console.WriteLine("Добро пожаловать в базу игроков."); | |
ShowAllInfo(_players); | |
ShowTopByLevel(); | |
ShowTopByStrength(); | |
} | |
private void ShowAllInfo(List<Player> players) | |
{ | |
foreach (var player in players) | |
{ | |
player.ShowInfo(); | |
} | |
Console.WriteLine(); | |
} | |
public void ShowTopByLevel() | |
{ | |
Console.WriteLine("Топ 3 игрока по уровню:"); | |
var top3ByLevel = _players.OrderByDescending(player => player.Level).Take(3).ToList(); | |
ShowAllInfo(top3ByLevel); | |
} | |
public void ShowTopByStrength() | |
{ | |
Console.WriteLine("Топ 3 игрока по силе:"); | |
var top3ByStrength = _players.OrderByDescending(player => player.Strength).Take(3).ToList(); | |
ShowAllInfo(top3ByStrength); | |
} | |
} | |
class Player | |
{ | |
public Player(string name, int level, int strength) | |
{ | |
Name = name; | |
Level = level; | |
Strength = strength; | |
} | |
public string Name { get; private set; } | |
public int Level { get; private set; } | |
public int Strength { get; private set; } | |
public void ShowInfo() | |
{ | |
Console.WriteLine($"Игрок: {Name}, Уровень: {Level}, Сила: {Strength}"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment