Skip to content

Instantly share code, notes, and snippets.

@plrtp68217
Last active June 3, 2025 16:20
Show Gist options
  • Save plrtp68217/453dfe671a5c1c1df89409142b4cd8e7 to your computer and use it in GitHub Desktop.
Save plrtp68217/453dfe671a5c1c1df89409142b4cd8e7 to your computer and use it in GitHub Desktop.
ДЗ: Бой с боссом
using System;
namespace Task
{
public class Programm
{
public static void Main(string[] args)
{
const string AttackCommand = "attack";
const string FireBallCommand = "fireBall";
const string ExplosionCommand = "explosion";
const string HealCommand = "heal";
string previosCommand = "";
string command;
string menuText = "Бой c боссом начинается!\n" +
$"{AttackCommand} - обычная атака\n" +
$"{FireBallCommand} - огненный шар\n" +
$"{ExplosionCommand} - взрыв (только после огеннного шара)\n" +
$"{HealCommand} - лечение\n" +
$"Босс за вами смотрит, рекомендуем писать команды правильно.";
int heroHealthMax = 100;
int heroHealth = heroHealthMax;
int heroDamage = 10;
int heroManaMax = 150;
int heroMana = heroManaMax;
int fireBallCost = 30;
int fireBallDamage = 20;
int explosionDamage = 40;
int healCount = 4;
int bossHealth = 100;
int bossDamage = 10;
Console.WriteLine(menuText);
while (heroHealth > 0 && bossHealth > 0)
{
Console.Write("Введите команду > ");
command = Console.ReadLine();
switch (command)
{
case AttackCommand:
previosCommand = command;
bossHealth -= heroDamage;
Console.WriteLine($"Герой нанес Боссу {heroDamage} урона обычной аттакой\n" +
$"Босс: {bossHealth} жизней"
);
break;
case FireBallCommand:
if (heroMana >= fireBallCost)
{
previosCommand = command;
heroMana -= fireBallCost;
bossHealth -= fireBallDamage;
Console.WriteLine($"Герой нанес Боссу {heroDamage} урона огненный шаром\n" +
$"Босс: {bossHealth} жизней"
);
}
else
{
Console.WriteLine("Маны больше нет!");
}
break;
case ExplosionCommand:
if (previosCommand == FireBallCommand)
{
previosCommand = command;
bossHealth -= explosionDamage;
Console.WriteLine($"Герой нанес Боссу {heroDamage} урона взрывом\n" +
$"Босс: {bossHealth} жизней"
);
}
else
{
Console.WriteLine("Для начала бросьте огенный шар!");
}
break;
case HealCommand:
if (healCount > 0)
{
previosCommand = command;
healCount--;
heroHealth = heroHealthMax;
heroMana = heroManaMax;
Console.WriteLine($"Герой принял аптечку, осталось {healCount} шт.\n" +
$"Герой: {heroHealth} жизней, {heroMana} маны"
);
}
else
{
Console.WriteLine("Аптечек больше нет!");
}
break;
default:
previosCommand = command;
heroHealth -= bossDamage;
Console.WriteLine($"Босс нанес Герою {bossDamage} урона\n" +
$"Герой: {heroHealth} жизней"
);
break;
}
}
if (heroHealth <= 0 && bossHealth <= 0)
{
Console.WriteLine("Ничья");
}
else if (heroHealth <= 0)
{
Console.WriteLine("Победил босс");
}
else if (bossHealth <= 0)
{
Console.WriteLine("Победил герой");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment