From abc86cd8c6cc58bba946e17998d12543c18aa9ae Mon Sep 17 00:00:00 2001 From: XomRK Date: Fri, 23 Oct 2026 16:47:49 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20wo?= =?UTF-8?q?rks/=D0=BB=D0=B0=D0=B1=D0=B0=20=E2=84=967=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=88=D0=B0=D1=80=D0=BF=D1=83.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- works/лаба №7 по шарпу.txt | 401 ------------------------------------- 1 file changed, 401 deletions(-) delete mode 100644 works/лаба №7 по шарпу.txt diff --git a/works/лаба №7 по шарпу.txt b/works/лаба №7 по шарпу.txt deleted file mode 100644 index 07197e5..0000000 --- a/works/лаба №7 по шарпу.txt +++ /dev/null @@ -1,401 +0,0 @@ - ЗАДАНИЕ №1 -using System; - -namespace PokemonHierarchy -{ - public class Pokemon - { - protected string name; - protected int level; - protected int hp; - - public string Name - { - get => name; - set => name = string.IsNullOrWhiteSpace(value) ? "Неизвестный покемон" : value; - } - - public int Level - { - get => level; - set => level = value < 1 ? 1 : value; - } - - public int HP - { - get => hp; - set => hp = value < 0 ? 0 : value; - } - - public Pokemon(string name, int level, int hp) - { - Name = name; - Level = level; - HP = hp; - } - - public virtual void Attack() - { - Console.WriteLine($"{Name} атакует базовой атакой!"); - } - - public void ShowInfo() - { - Console.Write($"{Name} (Ур. {Level}): "); - } - } - - public class Pikachu : Pokemon - { - public Pikachu(int level, int hp) : base("Пикачу", level, hp) { } - - public override void Attack() - { - Console.WriteLine("Пика-пика! Удар током!"); - } - } - - public class Wartortle : Pokemon - { - public Wartortle(int level, int hp) : base("Вартотл", level, hp) { } - - public override void Attack() - { - Console.WriteLine("Вар-вар! Водомет!"); - } - } - - public class Bulbasaur : Pokemon - { - public Bulbasaur(int level, int hp) : base("Бульбазавр", level, hp) { } - - public override void Attack() - { - Console.WriteLine("Бульба-бульба! Режущие листья!"); - } - } - - class Program - { - static void Main(string[] args) - { - Console.OutputEncoding = System.Text.Encoding.UTF8; - - Pokemon pikachu = new Pikachu(5, 45); - Pokemon wartortle = new Wartortle(16, 59); - Pokemon bulbasaur = new Bulbasaur(6, 45); - - Console.WriteLine("=== ПОКЕДЕКС: АТАКИ ==="); - - pikachu.ShowInfo(); - pikachu.Attack(); - - wartortle.ShowInfo(); - wartortle.Attack(); - - bulbasaur.ShowInfo(); - bulbasaur.Attack(); - - Console.ReadLine(); - } - } -} - - - - - - - - ЗАДАНИЕ №2 -using System; -using System.Collections.Generic; - -namespace PokemonTournament -{ - public abstract class Pokemon - { - protected string name; - protected int level; - protected int hp; - - private static int totalAttacksCount = 0; - public static int TotalAttacksCount => totalAttacksCount; - - public string Name - { - get => name; - set => name = string.IsNullOrWhiteSpace(value) ? "Неизвестный покемон" : value; - } - - public int Level - { - get => level; - set => level = value < 1 ? 1 : value; - } - - public int HP - { - get => hp; - set => hp = value < 0 ? 0 : value; - } - - public Pokemon(string name, int level, int hp) - { - Name = name; - Level = level; - HP = hp; - } - - public abstract void Attack(); - - public void ShowInfo() - { - Console.Write($"{Name} (Ур. {Level}): "); - } - - protected static void RegisterAttack() - { - totalAttacksCount++; - } - } - - public class Pikachu : Pokemon - { - public Pikachu(int level, int hp) : base("Пикачу", level, hp) { } - - public override void Attack() - { - Console.WriteLine("Пика-пика! Удар током!"); - } - } - - public class Wartortle : Pokemon - { - public Wartortle(int level, int hp) : base("Вартотл", level, hp) { } - - public override void Attack() - { - RegisterAttack(); - Console.WriteLine("Вар-вар! Водомет высокого давления!"); - } - } - - public class Bulbasaur : Pokemon - { - public Bulbasaur(int level, int hp) : base("Бульбазавр", level, hp) { } - - public override void Attack() - { - RegisterAttack(); - Console.WriteLine("Бульба! Листовой удар!"); - } - } - - public class Psyduck : Pokemon - { - public Psyduck(int level, int hp) : base("Псайдак", level, hp) { } - - public override void Attack() - { - RegisterAttack(); - Console.WriteLine("Псай-псай... Ментальный взрыв!"); - } - } - - class Program - { - static void Main(string[] args) - { - Console.OutputEncoding = System.Text.Encoding.UTF8; - - List tournamentParticipants = new List - { - new Pikachu(5, 45), - new Wartortle(16, 59), - new Bulbasaur(4, 45), - new Psyduck(8, 50) - }; - - Console.WriteLine("=== ТУРНИР: ВСЕ ПРОТИВ ВСЕХ ==="); - Console.WriteLine($"Всего покемонов: {tournamentParticipants.Count}"); - Console.WriteLine(); - Console.WriteLine("--- Раунд 1 ---"); - - foreach (Pokemon pokemon in tournamentParticipants) - { - pokemon.ShowInfo(); - pokemon.Attack(); - } - - Console.WriteLine(); - Console.WriteLine($"Всего атак проведено: {Pokemon.TotalAttacksCount}"); - - Console.ReadLine(); - } - } -} - - - - - - - - ЗАДАНИЕ №3 -using System; -using System.Collections.Generic; - -namespace PokemonInterfaces -{ - public interface IEvolvable - { - void Evolve(); - } - - public interface IFlyable - { - void Fly(); - } - - public abstract class Pokemon - { - protected string name; - protected int level; - protected int hp; - - public string Name { get => name; set => name = value; } - public int Level { get => level; set => level = value; } - public int HP { get => hp; set => hp = value; } - - public Pokemon(string name, int level, int hp) - { - Name = name; - Level = level; - HP = hp; - } - - public abstract void Attack(); - - public void ShowInfo() - { - Console.Write($"{Name} (Ур. {Level})"); - } - } - - public class Charmander : Pokemon, IEvolvable - { - public Charmander(int level, int hp) : base("Чармандер", level, hp) { } - - public override void Attack() - { - Console.WriteLine("Чар-чар! Огненный хвост!"); - } - - public void Evolve() - { - Console.WriteLine("Чармандер эволюционирует!"); - } - } - - public class Pidgeotto : Pokemon, IFlyable, IEvolvable - { - public Pidgeotto(int level, int hp) : base("Пиджеотто", level, hp) { } - - public override void Attack() - { - Console.WriteLine("Пидж! Стальные крылья!"); - } - - public void Fly() - { - Console.WriteLine("Пиджеотто взлетает!"); - } - - public void Evolve() - { - Console.WriteLine("Пиджеотто эволюционирует!"); - } - } - - public class Magikarp : Pokemon - { - public Magikarp(int level, int hp) : base("Магикарп", level, hp) { } - - public override void Attack() - { - Console.WriteLine("Маги-маги... Сплеш!"); - } - } - - class Program - { - static void Main(string[] args) - { - Console.OutputEncoding = System.Text.Encoding.UTF8; - - List pokedex = new List - { - new Charmander(6, 39), - new Pidgeotto(9, 63), - new Magikarp(3, 20) - }; - - Console.WriteLine("=== СПОСОБНОСТИ ПОКЕМОНОВ ===\n"); - - foreach (var pokemon in pokedex) - { - pokemon.ShowInfo(); - - List skills = new List { "атаковать" }; - - if (pokemon is IFlyable) skills.Add("летать"); - if (pokemon is IEvolvable) skills.Add("эволюционировать"); - - if (skills.Count == 1) - { - Console.WriteLine(" умеет: только атаковать"); - } - else - { - Console.WriteLine($" умеет: {string.Join(", ", skills)}"); - } - } - - Console.WriteLine("\n--- Проверка способностей ---"); - - int evolvableCount = 0; - int flyableCount = 0; - - foreach (var pokemon in pokedex) - { - bool hasSpecialSkills = false; - - if (pokemon is IFlyable flyable) - { - flyable.Fly(); - flyableCount++; - hasSpecialSkills = true; - } - - if (pokemon is IEvolvable evolvable) - { - evolvable.Evolve(); - evolvableCount++; - hasSpecialSkills = true; - } - - if (!hasSpecialSkills) - { - Console.WriteLine($"{pokemon.Name} ничего не умеет, кроме Splash."); - } - } - - Console.WriteLine("\nИтого:"); - Console.WriteLine($"Эволюционируют: {evolvableCount}"); - Console.WriteLine($"Летают: {flyableCount}"); - - Console.ReadLine(); - } - } -}