commit 8647a0c05cba57225411865fca50a7a89c52f90f Author: Katy328 Date: Fri Nov 27 10:06:11 2026 +0000 Загрузить файлы в «/» diff --git a/Pokemon.cs b/Pokemon.cs new file mode 100644 index 0000000..1319172 --- /dev/null +++ b/Pokemon.cs @@ -0,0 +1,302 @@ +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) } } + }; + } +} diff --git a/PokemonLinqLesson.csproj b/PokemonLinqLesson.csproj new file mode 100644 index 0000000..7ca9552 --- /dev/null +++ b/PokemonLinqLesson.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/PokemonLinqLesson.exe b/PokemonLinqLesson.exe new file mode 100644 index 0000000..8780036 Binary files /dev/null and b/PokemonLinqLesson.exe differ diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..c690439 --- /dev/null +++ b/Program.cs @@ -0,0 +1,90 @@ +using System.Text; +using PokemonLinqLesson; + +Console.OutputEncoding = Encoding.UTF8; + +var pokemons = PokemonSeed.Create(); + +// Уровень 1 +var heaviest = pokemons + .OrderByDescending(p => p.Weight) + .FirstOrDefault(); +Console.WriteLine($"Самый тяжёлый: {heaviest?.Name}: {heaviest?.Weight}"); + + +var shortNames = pokemons + .Where(p => p.Height < 10) + .OrderBy(p => p.Name) + .Select(p => p.Name) + .ToList(); +Console.Write("Списко легких покемонов: "); +Console.WriteLine(string.Join(", ", shortNames)); + + +var avgExp = pokemons.Average(p => p.BaseExperience); +Console.WriteLine($"Средний базовый опыт {avgExp:F2}"); + +//Уровень 2 + +var fireNames = pokemons + .Where(p => p.Types.Any(t => t.Slot == 1 && t.Name.ToLower() == "fire")) + .Select(p => p.Name) + .OrderBy(p => p) + .ToList(); +Console.Write("Покемоны конкретного типа: "); +Console.WriteLine(string.Join(", ", fireNames)); + + +var withHidden = pokemons + .Where(p => p.Abilities.Any(a => a.IsHidden)) + .ToList(); +Console.WriteLine($"Покемоны со скрытыми способностями: {withHidden.Count()}"); + + +var dualType = pokemons + .Where(p => p.Types.Count() == 2) + .ToList(); +Console.WriteLine($"Двухтипные покемоны: {dualType.Count()}"); + +//Уровень 3 + +var top3 = pokemons + .Select(p => new + { + Name = p.Name, + Attack = p.Stats + .Where(s => s.Name == "Attack") + .Select(s => s.BaseStat) + .FirstOrDefault() + }) + .OrderByDescending(x => x.Attack) + .Take(3) + .ToList(); +foreach (var x in top3) + Console.WriteLine($"Топовый покемон по атаке: {x.Name}: {x.Attack}"); + + +var groups = pokemons + .GroupBy(p => p.Types.Count()) + .Select(g => new + { + TypesCount = g.Key, + PokemonCount = g.Count() + }) + .OrderBy(g => g.PokemonCount) + .ToList(); +foreach (var g in groups) + Console.WriteLine($"Группировка по количеству типов: {g.TypesCount} тип(а): {g.PokemonCount}"); + + +var cards = 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(); +foreach (var c in cards) // для краткости первые 5 + Console.WriteLine($"Комплексная карточка покемона: {c.Name} | {string.Join("/", c.Types)} | способностей: {c.AbilitiesCount} | статы: {c.TotalStats}"); \ No newline at end of file