From abf05c267fc8ee436382cef53895509100ea2b06 Mon Sep 17 00:00:00 2001 From: adam1ch Date: Tue, 13 Oct 2026 16:00:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=207=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- works/lab 7/laba 7.cs | 125 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 works/lab 7/laba 7.cs diff --git a/works/lab 7/laba 7.cs b/works/lab 7/laba 7.cs new file mode 100644 index 0000000..568fb12 --- /dev/null +++ b/works/lab 7/laba 7.cs @@ -0,0 +1,125 @@ +namespace DefaultNamespace; + +public class laba_7 +using System; + +class Pokemon +{ + protected string name; + protected int level; + protected int hp; + + public string Name + { + get => name; + set + { + if (string.IsNullOrWhiteSpace(value)) + throw new ArgumentException("Имя покемона не может быть пустым."); + + name = value; + } + } + + public int Level + { + get => level; + set + { + if (value <= 0) + throw new ArgumentOutOfRangeException( + nameof(Level), "Уровень должен быть больше нуля."); + + level = value; + } + } + + public int HP + { + get => hp; + set + { + if (value < 0) + throw new ArgumentOutOfRangeException( + nameof(HP), "Количество HP не может быть отрицательным."); + + hp = value; + } + } + + public Pokemon(string name, int level, int hp) + { + Name = name; + Level = level; + HP = hp; + } + + public virtual void Attack() + { + Console.WriteLine("Покемон атакует!"); + } + + public void ShowInfo() + { + Console.Write($"{Name} (Ур. {Level}): "); + } +} + +class Pikachu : Pokemon +{ + public Pikachu(string name, int level, int hp) + : base(name, level, hp) + { + } + + public override void Attack() + { + Console.WriteLine("Пика-пика! Удар током!"); + } +} + +class Squirtle : Pokemon +{ + public Squirtle(string name, int level, int hp) + : base(name, level, hp) + { + } + + public override void Attack() + { + Console.WriteLine("Сквирт-сквирт! Водяной пистолет!"); + } +} + +class Charmander : Pokemon +{ + public Charmander(string name, int level, int hp) + : base(name, level, hp) + { + } + + public override void Attack() + { + Console.WriteLine("Чар-чар! Огненный хвост!"); + } +} + +class Program +{ + static void Main() + { + Pokemon pikachu = new Pikachu("Пикачу", 5, 35); + Pokemon squirtle = new Squirtle("Сквиртл", 7, 44); + Pokemon charmander = new Charmander("Чармандер", 6, 39); + + Pokemon[] pokemons = { pikachu, squirtle, charmander }; + + Console.WriteLine("=== ПОКЕДЕКС: АТАКИ ==="); + + foreach (Pokemon pokemon in pokemons) + { + pokemon.ShowInfo(); + pokemon.Attack(); + } + } +} \ No newline at end of file