Created
February 8, 2025 19:42
-
-
Save JunDmitry/6d24d97b9b9ced5ceb6781406752d4b0 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
namespace UnityLearn | |
{ | |
internal class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
int countPlayers = 100; | |
int countViewTop = 3; | |
PlayerFactory playerFactory = new(); | |
List<Player> players = playerFactory | |
.CreateCount(countPlayers) | |
.ToList(); | |
Console.WriteLine($"Top {countViewTop} players by level on the server: "); | |
players.OrderByDescending(player => player.Level) | |
.Take(countViewTop) | |
.ForEach(Console.WriteLine); | |
Console.WriteLine($"\n\nTop {countViewTop} players by strength on the server: "); | |
players.OrderByDescending(player => player.Strength) | |
.Take(countViewTop) | |
.ForEach(Console.WriteLine); | |
} | |
} | |
public class Player | |
{ | |
public Player(string name, int level, int strength) | |
{ | |
Name = name; | |
Level = level; | |
Strength = strength; | |
} | |
public string Name { get; } | |
public int Level { get; } | |
public int Strength { get; } | |
public override string ToString() | |
{ | |
return $"Name: {Name,-20} Level: {Level:000}, Strength: {Strength:0000}"; | |
} | |
} | |
public interface IFactory<T> | |
{ | |
T Create(); | |
} | |
public class PlayerFactory : IFactory<Player> | |
{ | |
private readonly string[] _prefixes; | |
private readonly string[] _bases; | |
private readonly string[] _suffixes; | |
private readonly int _minPlayerLevel; | |
private readonly int _maxPlayerLevel; | |
private readonly int _minPlayerStrength; | |
private readonly int _maxPlayerStrength; | |
public PlayerFactory() | |
{ | |
_prefixes = new string[] | |
{ | |
"Shadow", "Night", "Crimson", "Steel", "Golden", | |
"Silver", "Iron", "Mystic", "Epic", "Dark", | |
"Light", "Storm", "Frost", "Blaze", "Lunar", | |
"Solar", "Techno", "Cyber", "Alpha", "Omega", | |
"Elite", "Rogue", "Silent", "Swift", "Deadly", | |
"Venom", "Toxic", "Radiant", "Astral", "Cosmic", | |
"Void", "Phantom", "Ghost", "Legend", "Titan", | |
"Prime", "Nova", "Vortex", "Zero", "Chaos", | |
"Order", "Royal", "Savage", "True", "Fear", | |
"Brave", "Divine", "Eternal", "Infinite", "Final", | |
"Pixel", "Glitch", "Vector", "Binary", "Static", | |
"Quantum", "Digital", "Viral", "Code", "Data", | |
"Sync", "Echo", "Neo", "Proto", "Meta", | |
"Ultra", "Mega", "Omni", "Terra", "Aqua", | |
"Pyro", "Aero", "Geo", "Hydro", "Chrono", | |
"Astro", "Bio", "Nano", "Pseudo", "Anti", | |
"Hyper", "Infra", "Supra", "Trans", "Vice", | |
"Arch", "Mono", "Poly", "Pseudo", "Demi", | |
"Semi", "Sub", "Super", "Inter", "Re", | |
"Un", "Mis", "Dis", "Non", "Im" | |
}; | |
_bases = new string[] | |
{ | |
"ace", "arcane", "azure", "bandit", "blaze", | |
"bolt", "brave", "brute", "chaos", "cipher", | |
"cobra", "comet", "cosmic", "crimson", "cryptic", | |
"dark", "delta", "demon", "desire", "destiny", | |
"dragon", "dream", "echo", "elite", "ember", | |
"eternal", "falcon", "fear", "fiend", "fire", | |
"flame", "forest", "frost", "galaxy", "ghost", | |
"glory", "granite", "gravity", "hacker", "halo", | |
"hawk", "helix", "hunter", "ice", "illusion", | |
"inferno", "iron", "jade", "jinx", "karma", | |
"kinetic", "knight", "legend", "lunar", "magic", | |
"matrix", "midnight", "mirage", "mystic", "nebula", | |
"neon", "night", "nova", "onyx", "oracle", | |
"orbit", "phantom", "phoenix", "pixel", "plasma", | |
"pulse", "quantum", "quasar", "radiant", "rain", | |
"rebel", "rogue", "rune", "saber", "shadow", | |
"shifter", "sigma", "silence", "silver", "sky", | |
"solar", "soul", "spark", "spectral", "spider", | |
"storm", "stryker", "sun", "synth", "tango", | |
"terra", "titan", "toxic", "tracer", "tribal", | |
"umbra", "unseen", "valiant", "vector", "venom", | |
"vortex", "voyager", "warrior", "whisper", "winter", | |
"wraith", "xenon", "yggdrasil", "zenith", "zephyr", "zodiac" | |
}; | |
_suffixes = new string[] | |
{ | |
"slayer", "hunter", "warrior", "mage", "knight", | |
"rider", "striker", "guard", "scout", "wanderer", | |
"seeker", "champion", "lord", "king", "queen", | |
"god", "goddess", "avenger", "defender", "conqueror", | |
"destroyer", "vanquisher", "reaper", "specter", "wraith", | |
"bane", "shadow", "night", "storm", "frost", | |
"flame", "sun", "moon", "star", "comet", | |
"phoenix", "dragon", "wolf", "hawk", "serpent", | |
"viper", "venom", "blade", "axe", "hammer", | |
"bow", "arrow", "staff", "wand", "orb", | |
"tech", "cyber", "byte", "pixel", "bit", | |
"hacker", "coder", "glitch", "virus", "node", | |
"zero", "one", "data", "stream", "matrix", | |
"prime", "core", "nexus", "agent", "force", | |
"elite", "legend", "titan", "hero", "vanguard", | |
"omega", "alpha", "sigma", "delta", "gamma", | |
"rogue", "ninja", "assassin", "ghost", "phantom", | |
"spectre", "wraith", "shade", "seeker", "stalker", | |
"mystic", "oracle", "seer", "sage", "druid", | |
"prophet", "visionary", "enigma", "whisper", "echo" | |
}; | |
_minPlayerLevel = 1; | |
_maxPlayerLevel = 200; | |
_minPlayerStrength = 10; | |
_maxPlayerStrength = 9000; | |
} | |
public Player Create() | |
{ | |
string prefix = _prefixes[RandomGenerator.GenerateRandomNumber(_prefixes.Length)]; | |
string basis = _bases[RandomGenerator.GenerateRandomNumber(_bases.Length)]; | |
string suffix = _suffixes[RandomGenerator.GenerateRandomNumber(_suffixes.Length)]; | |
int level = RandomGenerator.GenerateRandomNumber(_minPlayerLevel, _maxPlayerLevel + 1); | |
int strength = RandomGenerator.GenerateRandomNumber(_minPlayerStrength, _maxPlayerStrength + 1); | |
return new Player($"{prefix}{basis}{suffix}", level, strength); | |
} | |
} | |
public static class RandomGenerator | |
{ | |
private static Random s_random = new Random(); | |
public static int GenerateRandomNumber(int max) | |
{ | |
return GenerateRandomNumber(0, max); | |
} | |
public static int GenerateRandomNumber(int min, int max) | |
{ | |
return s_random.Next(min, max); | |
} | |
} | |
public static class FactoryExtensions | |
{ | |
public static IEnumerable<T> CreateCount<T>(this IFactory<T> factory, int count) | |
{ | |
for (int i = 0; i < count; i++) | |
yield return factory.Create(); | |
} | |
} | |
public static class EnumerableExtensions | |
{ | |
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action) | |
{ | |
foreach (T item in collection) | |
action.Invoke(item); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment