Files

90 lines
2.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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}");