diff --git a/works/c/lab3/Program.cs b/works/c/lab3/Program.cs new file mode 100644 index 0000000..755a93c --- /dev/null +++ b/works/c/lab3/Program.cs @@ -0,0 +1,146 @@ +using System; +using System.Threading; + +namespace lab3 +{ + internal class Program + { + static void Main(string[] args) + { + while (true) + { + Console.Clear(); + Console.WriteLine("задание 1"); + Console.WriteLine("задание 2"); + Console.WriteLine("задание 3"); + Console.WriteLine("выход"); + Console.Write("\nвыберите номер задания: "); + + string choice = Console.ReadLine(); + Console.Clear(); + + switch (choice) + { + case "1": + Task1(); + break; + case "2": + Task2(); + break; + case "3": + Task3(); + break; + case "0": + return; + default: + Console.WriteLine("некорректный выбор!"); + break; + } + + Console.WriteLine("\nнажмите любую клавишу для продолжения..."); + Console.ReadKey(); + } + } + + static void Task1() + { + Console.WriteLine("задание 1"); + string pokemon1Name = "Пикачу"; + int pokemon1Hp = 50; + int pokemon1Attack = 12; + + string pokemon2Name = "Булбазавр"; + int pokemon2Hp = 55; + int pokemon2Attack = 10; + + int roundNumber = 1; + + Console.WriteLine("Приготовьтесь!"); + for (int i = 3; i >= roundNumber; i--) + { + Console.WriteLine(i + "..."); + Thread.Sleep(1000); + } + + Console.WriteLine("=== БОЙ НАЧИНАЕТСЯ ==="); + Console.WriteLine($"{pokemon1Name} (HP: {pokemon1Hp} / Атака: {pokemon1Attack}) VS {pokemon2Name} (HP: {pokemon2Hp} / Атака: {pokemon2Attack})"); + } + + static void Task2() + { + Console.WriteLine("здание 2."); + int command; + bool isValid; + + do + { + Console.Write("готовы начать бой? (1 - да, 0 - нет): "); + isValid = int.TryParse(Console.ReadLine(), out command) && (command == 1 || command == 0); + + if (!isValid) + { + Console.WriteLine("некорректная команда! попробуйте снова."); + } + + } while (!isValid); + + if (command == 0) + { + Console.WriteLine("Вы отменили бой!"); + return; + } + + Console.WriteLine("Бой начался! Удачи!"); + } + + static void Task3() + { + Console.WriteLine("задание 3."); + string pokemon1Name = "Пикачу"; + int pokemon1Hp = 50; + int pokemon1Attack = 12; + + string pokemon2Name = "Булбазавр"; + int pokemon2Hp = 55; + int pokemon2Attack = 10; + + int roundNumber = 1; + + while (pokemon1Hp > 0 && pokemon2Hp > 0) + { + Console.WriteLine($"--- Раунд {roundNumber} ---"); + + pokemon2Hp -= pokemon1Attack; + Console.WriteLine($"{pokemon1Name} наносит {pokemon1Attack} урона по {pokemon2Name}!"); + if (pokemon2Hp <= 0) + { + pokemon2Hp = 0; + Console.WriteLine($"{pokemon2Name} потерял сознание!"); + break; + } + + pokemon1Hp -= pokemon2Attack; + Console.WriteLine($"{pokemon2Name} наносит {pokemon2Attack} урона по {pokemon1Name}!"); + if (pokemon1Hp <= 0) + { + pokemon1Hp = 0; + Console.WriteLine($"{pokemon1Name} потерял сознание!"); + break; + } + + Console.WriteLine($"Итог раунда: {pokemon1Name} HP: {pokemon1Hp} | {pokemon2Name} HP: {pokemon2Hp}\n"); + roundNumber++; + } + + Console.WriteLine("=== бой окончен ==="); + if (pokemon1Hp > 0) + { + Console.WriteLine($"Победитель: {pokemon1Name}!"); + } + else + { + Console.WriteLine($"Победитель: {pokemon2Name}!"); + } + } + } +}