Обновить works/lab-03/lab_3.cs

This commit is contained in:
2026-09-30 11:54:24 +00:00
parent 474b971650
commit a831587b47
+113 -113
View File
@@ -1,113 +1,113 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Threading; using System.Threading;
namespace lab_3 namespace lab_3
{ {
internal class Program internal class Program
{ {
static string pokemon1Name = "Пикачу"; static string pokemon1Name = "Пикачу";
static int pokemon1Hp = 50; static int pokemon1Hp = 50;
static int pokemon1Attack = 12; static int pokemon1Attack = 12;
static string pokemon2Name = "Булбазавр"; static string pokemon2Name = "Булбазавр";
static int pokemon2Hp = 55; static int pokemon2Hp = 55;
static int pokemon2Attack = 10; static int pokemon2Attack = 10;
static int roundNumber = 1; static int roundNumber = 1;
static void Main(string[] args) static void Main(string[] args)
{ {
string userInput; string userInput;
do do
{ {
Console.WriteLine("1 -> Задание 1"); Console.WriteLine("1 -> Задание 1");
Console.WriteLine("2 -> Задание 2"); Console.WriteLine("2 -> Задание 2");
Console.WriteLine("3 -> Задание 3"); Console.WriteLine("3 -> Задание 3");
Console.WriteLine("4 -> Выход"); Console.WriteLine("4 -> Выход");
Console.Write("Выбор: "); Console.Write("Выбор: ");
userInput = Console.ReadLine(); userInput = Console.ReadLine();
switch (userInput) switch (userInput)
{ {
case "1": case "1":
part1(); part1();
break; break;
case "2": case "2":
part2(); part2();
break; break;
case "3": case "3":
part3(); part3();
break; break;
case "4": case "4":
part3(); part3();
break; break;
default: default:
Console.WriteLine("выбор не допустим"); Console.WriteLine("выбор не допустим");
break; break;
} }
} while (userInput != "4"); } while (userInput != "4");
} }
static void part1() static void part1()
{ {
Console.WriteLine("\nПриготовьтесь!"); Console.WriteLine("\nПриготовьтесь!");
for (int i = 3; i >0; i--) for (int i = 3; i >0; i--)
{ {
Console.WriteLine(i +"..."); Console.WriteLine(i +"...");
Thread.Sleep(1000); Thread.Sleep(1000);
} }
Console.WriteLine("=== БОЙ НАЧИНАЕТСЯ ==="); Console.WriteLine("=== БОЙ НАЧИНАЕТСЯ ===");
Console.WriteLine($"{pokemon1Name}({pokemon1Hp} | Атака: {pokemon1Attack}) VS {pokemon2Name}({pokemon2Hp} | Атака: {pokemon2Attack})\n"); Console.WriteLine($"{pokemon1Name}({pokemon1Hp} | Атака: {pokemon1Attack}) VS {pokemon2Name}({pokemon2Hp} | Атака: {pokemon2Attack})\n");
} }
static void part2() static void part2()
{ {
Console.Write("\nГотовы начать бой? (1 — Начать бой, 0 — Сдаться): "); Console.Write("\nГотовы начать бой? (1 — Начать бой, 0 — Сдаться): ");
string userInput2 = Console.ReadLine(); string userInput2 = Console.ReadLine();
var consoleText = ""; var consoleText = "";
do do
{ {
if (userInput2 == "1") if (userInput2 == "1")
{ {
consoleText = "Бой начинается!"; consoleText = "Бой начинается!";
} }
else if (userInput2 == "0") else if (userInput2 == "0")
{ {
consoleText = "...Никаких боев"; consoleText = "...Никаких боев";
} }
else else
{ {
consoleText = "Неверный ввод"; consoleText = "Неверный ввод";
} }
} while (userInput2 != "1" && userInput2 != "0"); } while (userInput2 != "1" && userInput2 != "0");
Console.WriteLine(consoleText + "\n"); Console.WriteLine(consoleText + "\n");
} }
static void part3() static void part3()
{ {
Console.WriteLine("\n=== БОЙ НАЧИНАЕТСЯ ==="); Console.WriteLine("\n=== БОЙ НАЧИНАЕТСЯ ===");
for (int i = 1; i <= 5; i++) for (int i = 1; i <= 5; i++)
{ {
Console.WriteLine($"---Раунд {i}---"); Console.WriteLine($"---Раунд {i}---");
Console.WriteLine($"{pokemon1Name} наносит {pokemon1Attack} урона по {pokemon2Name}!"); Console.WriteLine($"{pokemon1Name} наносит {pokemon1Attack} урона по {pokemon2Name}!");
pokemon2Hp -= pokemon1Attack; pokemon2Hp -= pokemon1Attack;
if (pokemon2Hp <= 0) if (pokemon2Hp <= 0)
{ {
pokemon2Hp = 0; pokemon2Hp = 0;
Console.WriteLine($"{pokemon2Name} потерял сознание!"); Console.WriteLine($"{pokemon2Name} потерял сознание!");
break; break;
} }
Console.WriteLine($"{pokemon2Name} наносит {pokemon2Attack} урона по {pokemon1Name}!"); Console.WriteLine($"{pokemon2Name} наносит {pokemon2Attack} урона по {pokemon1Name}!");
pokemon1Hp -= pokemon2Attack; pokemon1Hp -= pokemon2Attack;
if (pokemon1Hp <= 0) if (pokemon1Hp <= 0)
{ {
pokemon1Hp = 0; pokemon1Hp = 0;
Console.WriteLine($"{pokemon1Name} потерял сознание!"); Console.WriteLine($"{pokemon1Name} потерял сознание!");
break; break;
} }
Console.WriteLine($"Итог раунда: {pokemon1Name} HP: {pokemon1Hp} | {pokemon2Name} HP: {pokemon2Hp}\n"); Console.WriteLine($"Итог раунда: {pokemon1Name} HP: {pokemon1Hp} | {pokemon2Name} HP: {pokemon2Hp}\n");
Thread.Sleep(1000); Thread.Sleep(1000);
} }
} }
} }
} }