# Студент: Алиса Сакевич * **Группа:** 328 * **Курс:** ОДПО ## Полный исходный код (`Program.cs`) ```csharp using System; using System.Collections.Generic; using System.Linq; namespace PokemonLinqLesson { public class Pokemon { public int Id { get; set; } public string Name { get; set; } = string.Empty; public int Weight { get; set; } // гектограммы public int Height { get; set; } // дециметры public int BaseExperience { get; set; } public List Types { get; set; } = new(); public List Abilities { get; set; } = new(); public List Stats { get; set; } = new(); } public class PokemonType { public string Name { get; set; } = string.Empty; public int Slot { get; set; } // 1 — основной, 2 — дополнительный } public class Ability { public string Name { get; set; } = string.Empty; public bool IsHidden { get; set; } } public class Stat { public string Name { get; set; } = string.Empty; public int BaseStat { get; set; } } public static class PokemonSeed { private static PokemonType T(string name, int slot = 1) => new() { Name = name, Slot = slot }; private static Ability A(string name, bool hidden = false) => new() { Name = name, IsHidden = hidden }; private static Stat Attack(int value) => new() { Name = "Attack", BaseStat = value }; public static List Create() => new() { new() { Id = 1, Name = "bulbasaur", Weight = 69, Height = 7, BaseExperience = 64, Types = new() { T("grass", 1), T("poison", 2) }, Abilities = new() { A("overgrow"), A("chlorophyll", true) }, Stats = new() { Attack(49) } }, new() { Id = 2, Name = "ivysaur", Weight = 130, Height = 10, BaseExperience = 142, Types = new() { T("grass", 1), T("poison", 2) }, Abilities = new() { A("overgrow"), A("chlorophyll", true) }, Stats = new() { Attack(62) } }, new() { Id = 3, Name = "venusaur", Weight = 1000, Height = 20, BaseExperience = 236, Types = new() { T("grass", 1), T("poison", 2) }, Abilities = new() { A("overgrow"), A("chlorophyll", true) }, Stats = new() { Attack(82) } }, new() { Id = 4, Name = "charmander", Weight = 85, Height = 6, BaseExperience = 62, Types = new() { T("fire", 1) }, Abilities = new() { A("blaze"), A("solar-power", true) }, Stats = new() { Attack(52) } }, new() { Id = 5, Name = "charmeleon", Weight = 190, Height = 11, BaseExperience = 142, Types = new() { T("fire", 1) }, Abilities = new() { A("blaze"), A("solar-power", true) }, Stats = new() { Attack(64) } }, new() { Id = 6, Name = "charizard", Weight = 905, Height = 17, BaseExperience = 240, Types = new() { T("fire", 1), T("flying", 2) }, Abilities = new() { A("blaze"), A("solar-power", true) }, Stats = new() { Attack(84) } }, new() { Id = 7, Name = "squirtle", Weight = 90, Height = 5, BaseExperience = 63, Types = new() { T("water", 1) }, Abilities = new() { A("torrent"), A("rain-dish", true) }, Stats = new() { Attack(48) } }, new() { Id = 8, Name = "wartortle", Weight = 225, Height = 10, BaseExperience = 142, Types = new() { T("water", 1) }, Abilities = new() { A("torrent"), A("rain-dish", true) }, Stats = new() { Attack(63) } }, new() { Id = 9, Name = "blastoise", Weight = 855, Height = 16, BaseExperience = 239, Types = new() { T("water", 1) }, Abilities = new() { A("torrent"), A("rain-dish", true) }, Stats = new() { Attack(83) } }, new() { Id = 10, Name = "caterpie", Weight = 29, Height = 3, BaseExperience = 39, Types = new() { T("bug", 1) }, Abilities = new() { A("shield-dust"), A("run-away", true) }, Stats = new() { Attack(30) } }, new() { Id = 11, Name = "metapod", Weight = 99, Height = 7, BaseExperience = 72, Types = new() { T("bug", 1) }, Abilities = new() { A("shed-skin") }, Stats = new() { Attack(20) } }, new() { Id = 12, Name = "butterfree", Weight = 320, Height = 11, BaseExperience = 178, Types = new() { T("bug", 1), T("flying", 2) }, Abilities = new() { A("compound-eyes"), A("tinted-lens", true) }, Stats = new() { Attack(45) } }, new() { Id = 13, Name = "weedle", Weight = 32, Height = 3, BaseExperience = 39, Types = new() { T("bug", 1), T("poison", 2) }, Abilities = new() { A("shield-dust"), A("run-away", true) }, Stats = new() { Attack(35) } }, new() { Id = 14, Name = "kakuna", Weight = 100, Height = 6, BaseExperience = 72, Types = new() { T("bug", 1), T("poison", 2) }, Abilities = new() { A("shed-skin") }, Stats = new() { Attack(25) } }, new() { Id = 15, Name = "beedrill", Weight = 295, Height = 10, BaseExperience = 178, Types = new() { T("bug", 1), T("poison", 2) }, Abilities = new() { A("swarm"), A("sniper", true) }, Stats = new() { Attack(90) } }, new() { Id = 16, Name = "pidgey", Weight = 18, Height = 3, BaseExperience = 50, Types = new() { T("normal", 1), T("flying", 2) }, Abilities = new() { A("keen-eye"), A("tangled-feet"), A("big-pecks", true) }, Stats = new() { Attack(45) } }, new() { Id = 17, Name = "pidgeotto", Weight = 300, Height = 11, BaseExperience = 122, Types = new() { T("normal", 1), T("flying", 2) }, Abilities = new() { A("keen-eye"), A("tangled-feet"), A("big-pecks", true) }, Stats = new() { Attack(60) } }, new() { Id = 18, Name = "pidgeot", Weight = 395, Height = 15, BaseExperience = 216, Types = new() { T("normal", 1), T("flying", 2) }, Abilities = new() { A("keen-eye"), A("tangled-feet"), A("big-pecks", true) }, Stats = new() { Attack(80) } }, new() { Id = 19, Name = "rattata", Weight = 35, Height = 3, BaseExperience = 51, Types = new() { T("normal", 1) }, Abilities = new() { A("run-away"), A("guts"), A("hustle", true) }, Stats = new() { Attack(56) } }, new() { Id = 20, Name = "raticate", Weight = 185, Height = 7, BaseExperience = 145, Types = new() { T("normal", 1) }, Abilities = new() { A("run-away"), A("guts"), A("hustle", true) }, Stats = new() { Attack(81) } }, new() { Id = 21, Name = "spearow", Weight = 20, Height = 3, BaseExperience = 52, Types = new() { T("normal", 1), T("flying", 2) }, Abilities = new() { A("keen-eye"), A("sniper", true) }, Stats = new() { Attack(60) } }, new() { Id = 22, Name = "fearow", Weight = 380, Height = 12, BaseExperience = 155, Types = new() { T("normal", 1), T("flying", 2) }, Abilities = new() { A("keen-eye"), A("sniper", true) }, Stats = new() { Attack(90) } }, new() { Id = 23, Name = "ekans", Weight = 69, Height = 20, BaseExperience = 58, Types = new() { T("poison", 1) }, Abilities = new() { A("intimidate"), A("shed-skin"), A("unnerve", true) }, Stats = new() { Attack(60) } }, new() { Id = 24, Name = "arbok", Weight = 650, Height = 35, BaseExperience = 157, Types = new() { T("poison", 1) }, Abilities = new() { A("intimidate"), A("shed-skin"), A("unnerve", true) }, Stats = new() { Attack(95) } }, new() { Id = 25, Name = "pikachu", Weight = 60, Height = 4, BaseExperience = 112, Types = new() { T("electric", 1) }, Abilities = new() { A("static"), A("lightning-rod", true) }, Stats = new() { Attack(55) } }, new() { Id = 26, Name = "raichu", Weight = 300, Height = 8, BaseExperience = 218, Types = new() { T("electric", 1) }, Abilities = new() { A("static"), A("lightning-rod", true) }, Stats = new() { Attack(90) } }, new() { Id = 27, Name = "sandshrew", Weight = 120, Height = 6, BaseExperience = 60, Types = new() { T("ground", 1) }, Abilities = new() { A("sand-veil"), A("sand-rush", true) }, Stats = new() { Attack(75) } }, new() { Id = 28, Name = "sandslash", Weight = 295, Height = 10, BaseExperience = 158, Types = new() { T("ground", 1) }, Abilities = new() { A("sand-veil"), A("sand-rush", true) }, Stats = new() { Attack(100) } }, new() { Id = 29, Name = "nidoran-f", Weight = 70, Height = 4, BaseExperience = 55, Types = new() { T("poison", 1) }, Abilities = new() { A("poison-point"), A("rivalry"), A("hustle", true) }, Stats = new() { Attack(47) } }, new() { Id = 30, Name = "nidorina", Weight = 200, Height = 8, BaseExperience = 128, Types = new() { T("poison", 1) }, Abilities = new() { A("poison-point"), A("rivalry"), A("hustle", true) }, Stats = new() { Attack(62) } }, new() { Id = 31, Name = "nidoqueen", Weight = 600, Height = 13, BaseExperience = 227, Types = new() { T("poison", 1), T("ground", 2) }, Abilities = new() { A("poison-point"), A("rivalry"), A("sheer-force", true) }, Stats = new() { Attack(92) } }, new() { Id = 32, Name = "nidoran-m", Weight = 90, Height = 5, BaseExperience = 55, Types = new() { T("poison", 1) }, Abilities = new() { A("poison-point"), A("rivalry"), A("hustle", true) }, Stats = new() { Attack(57) } }, new() { Id = 33, Name = "nidorino", Weight = 195, Height = 9, BaseExperience = 128, Types = new() { T("poison", 1) }, Abilities = new() { A("poison-point"), A("rivalry"), A("hustle", true) }, Stats = new() { Attack(72) } }, new() { Id = 34, Name = "nidoking", Weight = 620, Height = 14, BaseExperience = 227, Types = new() { T("poison", 1), T("ground", 2) }, Abilities = new() { A("poison-point"), A("rivalry"), A("sheer-force", true) }, Stats = new() { Attack(102) } }, new() { Id = 35, Name = "clefairy", Weight = 75, Height = 6, BaseExperience = 113, Types = new() { T("fairy", 1) }, Abilities = new() { A("cute-charm"), A("magic-guard"), A("friend-guard", true) }, Stats = new() { Attack(45) } }, new() { Id = 36, Name = "clefable", Weight = 400, Height = 13, BaseExperience = 217, Types = new() { T("fairy", 1) }, Abilities = new() { A("cute-charm"), A("magic-guard"), A("unaware", true) }, Stats = new() { Attack(70) } }, new() { Id = 37, Name = "vulpix", Weight = 99, Height = 6, BaseExperience = 60, Types = new() { T("fire", 1) }, Abilities = new() { A("flash-fire"), A("drought", true) }, Stats = new() { Attack(41) } }, new() { Id = 38, Name = "ninetales", Weight = 199, Height = 11, BaseExperience = 177, Types = new() { T("fire", 1) }, Abilities = new() { A("flash-fire"), A("drought", true) }, Stats = new() { Attack(76) } }, new() { Id = 39, Name = "jigglypuff", Weight = 55, Height = 5, BaseExperience = 95, Types = new() { T("normal", 1), T("fairy", 2) }, Abilities = new() { A("cute-charm"), A("competitive"), A("friend-guard", true) }, Stats = new() { Attack(45) } }, new() { Id = 40, Name = "wigglytuff", Weight = 120, Height = 10, BaseExperience = 196, Types = new() { T("normal", 1), T("fairy", 2) }, Abilities = new() { A("cute-charm"), A("competitive"), A("frisk", true) }, Stats = new() { Attack(70) } }, new() { Id = 41, Name = "zubat", Weight = 75, Height = 8, BaseExperience = 49, Types = new() { T("poison", 1), T("flying", 2) }, Abilities = new() { A("inner-focus"), A("infiltrator", true) }, Stats = new() { Attack(45) } }, new() { Id = 42, Name = "golbat", Weight = 550, Height = 16, BaseExperience = 159, Types = new() { T("poison", 1), T("flying", 2) }, Abilities = new() { A("inner-focus"), A("infiltrator", true) }, Stats = new() { Attack(80) } }, new() { Id = 43, Name = "oddish", Weight = 54, Height = 5, BaseExperience = 64, Types = new() { T("grass", 1), T("poison", 2) }, Abilities = new() { A("chlorophyll"), A("run-away", true) }, Stats = new() { Attack(50) } }, new() { Id = 44, Name = "gloom", Weight = 86, Height = 8, BaseExperience = 138, Types = new() { T("grass", 1), T("poison", 2) }, Abilities = new() { A("chlorophyll"), A("stench", true) }, Stats = new() { Attack(65) } }, new() { Id = 45, Name = "vileplume", Weight = 186, Height = 12, BaseExperience = 221, Types = new() { T("grass", 1), T("poison", 2) }, Abilities = new() { A("chlorophyll"), A("effect-spore", true) }, Stats = new() { Attack(80) } }, new() { Id = 46, Name = "paras", Weight = 54, Height = 3, BaseExperience = 57, Types = new() { T("bug", 1), T("grass", 2) }, Abilities = new() { A("effect-spore"), A("dry-skin"), A("damp", true) }, Stats = new() { Attack(70) } }, new() { Id = 47, Name = "parasect", Weight = 295, Height = 10, BaseExperience = 142, Types = new() { T("bug", 1), T("grass", 2) }, Abilities = new() { A("effect-spore"), A("dry-skin"), A("damp", true) }, Stats = new() { Attack(95) } }, new() { Id = 48, Name = "venonat", Weight = 300, Height = 10, BaseExperience = 61, Types = new() { T("bug", 1), T("poison", 2) }, Abilities = new() { A("compound-eyes"), A("tinted-lens"), A("run-away", true) }, Stats = new() { Attack(55) } }, new() { Id = 49, Name = "venomoth", Weight = 125, Height = 15, BaseExperience = 158, Types = new() { T("bug", 1), T("poison", 2) }, Abilities = new() { A("shield-dust"), A("tinted-lens"), A("wonder-skin", true) }, Stats = new() { Attack(65) } }, new() { Id = 50, Name = "diglett", Weight = 8, Height = 2, BaseExperience = 53, Types = new() { T("ground", 1) }, Abilities = new() { A("sand-veil"), A("arena-trap"), A("sand-force", true) }, Stats = new() { Attack(55) } } }; } /* class Program { static void Main(string[] args) { var pokemons = PokemonSeed.Create(); var heaviest = pokemons .OrderByDescending(p => p.Weight) .FirstOrDefault(); Console.WriteLine($"{heaviest?.Name}: {heaviest?.Weight}"); } } */ /* class Program { static void Main(string[] args) { var pokemons = PokemonSeed.Create(); var height = pokemons .Where(p => p.Height < 10) .OrderBy(p => p.Name) .Select(p => p.Name) .ToList(); Console.WriteLine("Покемоны с ростом меньше 10 дм"); foreach (var name in height) { Console.WriteLine($"- {name}"); } } } */ /* class Program { static void Main(string[] args) { double averageExperience = PokemonSeed.Create() .Average(p => p.BaseExperience); Console.WriteLine($"Средний базовый опыт: {averageExperience}"); } } */ /* class Program { static void Main(string[] args) { var pokemons = PokemonSeed.Create(); var fire = pokemons .Where(p => p.Types.Any(t => t.Slot == 1 && t.Name.Equals("fire", StringComparison.OrdinalIgnoreCase))) .Select(p => p.Name) .ToList(); Console.WriteLine("Покемоны с основным типом Fire:"); foreach (var name in fire) { Console.WriteLine($"- {name}"); } } } */ /* class Program { static void Main(string[] args) { var pokemons = PokemonSeed.Create(); var IsHidden = pokemons .Where(p => p.Abilities.Any(a => a.IsHidden)) .ToList(); Console.WriteLine("Покемоны со скрытыми способностями:"); foreach (var pokemon in IsHidden) { Console.WriteLine($"- {pokemon.Name}"); } } } */ /* class Program { static void Main(string[] args) { var pokemons = PokemonSeed.Create(); var PokemonTypes = pokemons .Where(p => p.Types.Count == 2) .ToList(); Console.WriteLine("Двухтипыные покемоны"); foreach (var pokemon in PokemonTypes) { Console.WriteLine($"- {pokemon.Name}"); } } } */ /* class Program { static void Main(string[] args) { var pokemons = PokemonSeed.Create(); var Top3Attack = pokemons .Where(p => p.Stats.Any(s => s.Name == "Attack")) .OrderByDescending(p => p.Stats.First(s => s.Name == "Attack").BaseStat) .Take(3) .Select(p => new { p.Name, Attack = p.Stats.First(s => s.Name == "Attack").BaseStat }) .ToList(); Console.WriteLine("Топ-3 покемона по атаке"); foreach (var pokemon in Top3Attack) { Console.WriteLine($"- {pokemon.Name}"); } } } */ /* class Program { static void Main(string[] args) { var pokemons = PokemonSeed.Create(); var GroupeTypeCount = pokemons .GroupBy(p => p.Types.Count) .Select(g => new { TypesCount = g.Key, PokemonsCount = g.Count() }) .ToList(); Console.WriteLine("Группировка по количеству типов"); foreach (var g in GroupeTypeCount) { Console.WriteLine($"- Типы: {g.TypesCount} -> Покемоны: {g.PokemonsCount}"); } } } */ class Program { static void Main(string[] args) { var pokemons = PokemonSeed.Create(); var pokemonCards = pokemons .Select(p => new { Name = p.Name, Types = p.Types.Select(t => t.Name).ToList(), AbilitiesCount = p.Abilities.Count, TotalStats = p.Stats.Sum(s => s.BaseStat) }) .ToList(); Console.WriteLine("Комплексные карточки покемонов:"); foreach (var card in pokemonCards) { string typesList = string.Join(", ", card.Types); Console.WriteLine($"Name: {card.Name} | Types: {typesList} | Abilities: {card.AbilitiesCount} | Stats: {card.TotalStats}"); } } } ```