diff --git a/works/lab-06/ConsoleApp1/ConsoleApp1.sln b/works/lab-06/ConsoleApp1/ConsoleApp1.sln new file mode 100644 index 0000000..33c4179 --- /dev/null +++ b/works/lab-06/ConsoleApp1/ConsoleApp1.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{D959845F-02D5-4C96-9BED-432306BA3585}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D959845F-02D5-4C96-9BED-432306BA3585}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D959845F-02D5-4C96-9BED-432306BA3585}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D959845F-02D5-4C96-9BED-432306BA3585}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D959845F-02D5-4C96-9BED-432306BA3585}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/works/lab-06/ConsoleApp1/ConsoleApp1/ConsoleApp1.csproj b/works/lab-06/ConsoleApp1/ConsoleApp1/ConsoleApp1.csproj new file mode 100644 index 0000000..6c1dc92 --- /dev/null +++ b/works/lab-06/ConsoleApp1/ConsoleApp1/ConsoleApp1.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/works/lab-06/ConsoleApp1/ConsoleApp1/Program.cs b/works/lab-06/ConsoleApp1/ConsoleApp1/Program.cs new file mode 100644 index 0000000..bec0040 --- /dev/null +++ b/works/lab-06/ConsoleApp1/ConsoleApp1/Program.cs @@ -0,0 +1,170 @@ +using System; + +namespace PokemonLab +{ + class Pokemon + { + private string name; + private int level; + private int hp; + + public static int Count { get; private set; } = 0; + + public string Name + { + get { return name; } + set + { + if (string.IsNullOrWhiteSpace(value)) + name = "Безымянный"; + else + name = value; + } + } + + public int Level + { + get { return level; } + set + { + if (value < 1) level = 1; + else if (value > 100) level = 100; + else level = value; + } + } + + public int HP + { + get { return hp; } + set + { + if (value < 0) hp = 0; + else if (value > 100) hp = 100; + else hp = value; + } + } + public Pokemon(string name, int level, int hp) + { + Name = name; + Level = level; + HP = hp; + Count++; + } + + public Pokemon() : this("Безымянный", 1, 100) + { + } + + public void TakeDamage(int damage) + { + if (damage < 0) damage = 0; + HP = HP - damage; + } + + public void Heal() + { + HP = 100; + } + + public void LevelUp() + { + Level = Level + 1; + } + + public void ShowInfo() + { + Console.WriteLine($"Имя: {Name}, Уровень: {Level}, HP: {HP}"); + } + + public void Battle(Pokemon enemy) + { + Console.WriteLine($"\n{Name} (Ур. {Level}, HP {HP}) против {enemy.Name} (Ур. {enemy.Level}, HP {enemy.HP})"); + + Pokemon winner; + Pokemon loser; + + if (Level > enemy.Level) + { + winner = this; + loser = enemy; + } + else if (enemy.Level > Level) + { + winner = enemy; + loser = this; + } + else + { + if (HP >= enemy.HP) + { + winner = this; + loser = enemy; + } + else + { + winner = enemy; + loser = this; + } + } + int damage = winner.Level; + loser.TakeDamage(damage); + + Console.WriteLine($"{winner.Name} побеждает! {loser.Name} теряет {damage} HP."); + Console.WriteLine($"Победитель: {winner.Name}. Осталось HP: {winner.HP}"); + Console.WriteLine($"Побеждённый: {loser.Name}. Осталось HP: {loser.HP}"); + } + } + class Program + { + static void Main(string[] args) + { + Console.OutputEncoding = System.Text.Encoding.UTF8; + + // ЗАДАНИЕ 1 + Console.WriteLine("=== ПОКЕДЕКС ==="); + Pokemon pika = new Pokemon("Пикачу", 5, 100); + Pokemon squirtle = new Pokemon("Сквиртл", 7, 90); + + Console.Write("1. "); + pika.ShowInfo(); + Console.Write("2. "); + squirtle.ShowInfo(); + + // ЗАДАНИЕ 2 + Console.WriteLine("\n=== ПРОВЕРКА ИНКАПСУЛЯЦИИ ==="); + + Pokemon test = new Pokemon("Тест", 10, 100); + + Console.WriteLine("Попытка установить HP = -50..."); + test.HP = -50; + Console.WriteLine($"Текущее HP: {test.HP} (защита сработала)"); + + test.TakeDamage(30); + Console.WriteLine($"Покемон получил 30 урона. HP: {test.HP}"); + + test.Heal(); + Console.WriteLine($"Покемон вылечился. HP: {test.HP}"); + Console.WriteLine("\nСоздание покемона-яйца (конструктор без параметров):"); + Pokemon egg = new Pokemon(); + egg.ShowInfo(); + + // ЗАДАНИЕ 3 + Console.WriteLine("\n=== ПОКЕДЕКС: СТАТИСТИКА ==="); + Pokemon charmander = new Pokemon("Чармандер", 6, 95); + + Console.WriteLine($"Создано покемонов: {Pokemon.Count}"); + + Console.WriteLine("\n=== БИТВА ==="); + pika.Battle(squirtle); + + Console.WriteLine($"\nСостояние после боя:"); + Console.Write("Пикачу: "); + pika.ShowInfo(); + Console.Write("Сквиртл: "); + squirtle.ShowInfo(); + + Console.WriteLine("\nНажмите любую клавишу для выхода..."); + Console.ReadKey(); + } + } +} \ No newline at end of file