generated from admin/template
stage03
This commit is contained in:
@@ -0,0 +1,203 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
// ЭТАП 1 ввод абстрактных данных и отрисовка карточки
|
||||||
|
Console.WriteLine("======================================================================");
|
||||||
|
Console.WriteLine("ИНИЦИАЛИЗА КАРТОЧКИ ПОКЕМОНА");
|
||||||
|
Console.WriteLine("----------------------------------------------------------------------");
|
||||||
|
|
||||||
|
Console.Write("Введите стадию развития: ");
|
||||||
|
string stage = Console.ReadLine();
|
||||||
|
|
||||||
|
Console.Write("Введите имя покемона: ");
|
||||||
|
string name = Console.ReadLine();
|
||||||
|
|
||||||
|
Console.Write("Введите вид покемона: ");
|
||||||
|
string category = Console.ReadLine();
|
||||||
|
|
||||||
|
Console.Write("Введите название 1-й атаки: ");
|
||||||
|
string attack1Name = Console.ReadLine();
|
||||||
|
|
||||||
|
Console.Write("Введите эффект 1-й атаки: ");
|
||||||
|
string attack1Desc = Console.ReadLine();
|
||||||
|
|
||||||
|
Console.Write("Введите базовый урон 1-й атаки: ");
|
||||||
|
int attack1BaseDamage = int.Parse(Console.ReadLine());
|
||||||
|
|
||||||
|
Console.Write("Введите название 2-й атаки: ");
|
||||||
|
string attack2Name = Console.ReadLine();
|
||||||
|
|
||||||
|
Console.Write("Введите эффект 2-й атаки: ");
|
||||||
|
string attack2Desc = Console.ReadLine();
|
||||||
|
|
||||||
|
Console.Write("Введите базовый урон 2-й атаки: ");
|
||||||
|
int attack2BaseDamage = int.Parse(Console.ReadLine());
|
||||||
|
|
||||||
|
Console.Write("Введите уязвимость: ");
|
||||||
|
string weakness = Console.ReadLine();
|
||||||
|
|
||||||
|
Console.Write("Введите устойчивость: ");
|
||||||
|
string resistance = Console.ReadLine();
|
||||||
|
|
||||||
|
Console.Write("Введите текущее HP: ");
|
||||||
|
int hp = int.Parse(Console.ReadLine());
|
||||||
|
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
Console.WriteLine("======================================================================");
|
||||||
|
Console.WriteLine($"[{stage}] {name,-45} ОЖ: {hp}");
|
||||||
|
Console.WriteLine("----------------------------------------------------------------------");
|
||||||
|
Console.WriteLine($"Вид: {category}");
|
||||||
|
Console.WriteLine("----------------------------------------------------------------------");
|
||||||
|
Console.WriteLine($"[Атака 1] {attack1Name,-40} Урон: {attack1BaseDamage}");
|
||||||
|
Console.WriteLine($"Эффект: {attack1Desc}");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine($"[Атака 2] {attack2Name,-40} Урон: {attack2BaseDamage}+");
|
||||||
|
Console.WriteLine($"Эффект: {attack2Desc}");
|
||||||
|
Console.WriteLine("----------------------------------------------------------------------");
|
||||||
|
Console.WriteLine($"Слабость: {weakness} | Устойчивость: {resistance}");
|
||||||
|
Console.WriteLine("======================================================================\n");
|
||||||
|
|
||||||
|
// ЭТАП 2 переменные врага и предстартовый отсчёт
|
||||||
|
string enemyName = "Булбазавр";
|
||||||
|
int enemyHp = 70;
|
||||||
|
int enemyBaseDamage = 15;
|
||||||
|
int roundNumber = 1;
|
||||||
|
bool isEnemyDebuffed = false;
|
||||||
|
|
||||||
|
Console.WriteLine("Приготовьтесь к дуэли!");
|
||||||
|
for (int i = 3; i >= 1; i--)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{i}...");
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
Console.WriteLine($"=== СТАРТ ДУЭЛИ: {name} (HP: {hp}) VS {enemyName} (HP: {enemyHp}) ===");
|
||||||
|
|
||||||
|
// ЭТАП 3 игровой цикл пошаговой дуэли
|
||||||
|
while (hp > 0 && enemyHp > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"\n--- Раунд {roundNumber} ---");
|
||||||
|
|
||||||
|
// валидация выбора действия
|
||||||
|
int actionChoice;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Console.Write($"Выберите действие (1 - {attack1Name}, 2 - {attack2Name}): ");
|
||||||
|
actionChoice = int.Parse(Console.ReadLine());
|
||||||
|
} while (actionChoice != 1 && actionChoice != 2);
|
||||||
|
|
||||||
|
// ход игрока
|
||||||
|
int playerDamage = 0;
|
||||||
|
if (actionChoice == 1)
|
||||||
|
{
|
||||||
|
Console.Write($"[{attack1Name}] Проверка условия спецэффекта (1 - Сработал, 0 - Нет): ");
|
||||||
|
int effectResult = int.Parse(Console.ReadLine());
|
||||||
|
|
||||||
|
playerDamage = attack1BaseDamage;
|
||||||
|
if (effectResult == 1)
|
||||||
|
{
|
||||||
|
isEnemyDebuffed = true;
|
||||||
|
Console.WriteLine($"Результат: Спецэффект сработал! {enemyName} потерял возможность атаковать!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Результат: Спецэффект не сработал.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (actionChoice == 2)
|
||||||
|
{
|
||||||
|
Console.Write($"[{attack2Name}] Проверка условия спецэффекта (1 - Критический урон, 0 - Обычный): ");
|
||||||
|
int bonusResult = int.Parse(Console.ReadLine());
|
||||||
|
|
||||||
|
if (bonusResult == 1)
|
||||||
|
{
|
||||||
|
playerDamage = attack2BaseDamage + 10;
|
||||||
|
Console.WriteLine($"Результат: Условие выполнено! Нанесен усиленный урон: {playerDamage}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerDamage = attack2BaseDamage;
|
||||||
|
Console.WriteLine($"Результат: Базовый урон: {playerDamage}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// урон врагу
|
||||||
|
enemyHp -= playerDamage;
|
||||||
|
|
||||||
|
// проверка нокаута врага
|
||||||
|
if (enemyHp <= 0)
|
||||||
|
{
|
||||||
|
enemyHp = 0;
|
||||||
|
Console.WriteLine($"{enemyName} нокаутирован!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ход лоха
|
||||||
|
if (isEnemyDebuffed)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{enemyName} пропускает ход из-за эффекта атаки!");
|
||||||
|
isEnemyDebuffed = false; // сброс
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.Write("Выберите тип атаки противника (1 - Уязвимость, 2 - Устойчивость, 3 - Обычный): ");
|
||||||
|
int attackType = int.Parse(Console.ReadLine());
|
||||||
|
|
||||||
|
int finalIncomingDamage = 0;
|
||||||
|
switch (attackType)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
finalIncomingDamage = enemyBaseDamage * 2;
|
||||||
|
Console.WriteLine($"Расчёт: Уязвимость ({weakness})! Урон удваивается (x2).");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
finalIncomingDamage = enemyBaseDamage - 20;
|
||||||
|
if (finalIncomingDamage < 0)
|
||||||
|
{
|
||||||
|
finalIncomingDamage = 0;
|
||||||
|
}
|
||||||
|
Console.WriteLine($"Расчёт: Устойчивость ({resistance})! Урон уменьшается на 20.");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
finalIncomingDamage = enemyBaseDamage;
|
||||||
|
Console.WriteLine("Расчёт: Обычный тип! Урон наносится без изменений.");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Console.WriteLine("Ошибка: Выбран неизвестный тип атаки!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
hp -= finalIncomingDamage;
|
||||||
|
|
||||||
|
// проверка нокаута игрока
|
||||||
|
if (hp <= 0)
|
||||||
|
{
|
||||||
|
hp = 0;
|
||||||
|
Console.WriteLine($"{name} нокаутирован!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Итог
|
||||||
|
Console.WriteLine($"Итог раунда: {name} HP: {hp} | {enemyName} HP: {enemyHp}");
|
||||||
|
roundNumber++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ЭТАП 4 подведение итогов боя
|
||||||
|
Console.WriteLine("\n======================================================================");
|
||||||
|
Console.WriteLine("=== ДУЭЛЬ ОКОНЧЕНА ===");
|
||||||
|
if (hp > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Победитель: {name}!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Победитель: {enemyName}!");
|
||||||
|
}
|
||||||
|
Console.WriteLine("======================================================================");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# stage C# №3
|
||||||
|
|
||||||
|
## 📌 Тема
|
||||||
|
Циклы и управление потоком выполнения. Игровой цикл пошагового боя
|
||||||
|
## 📝 Описание
|
||||||
|
В рамках данной лабораторной работы производится рефакторинг и обобщение кода из Части 1 (оцифровка и форматированный вывод карточки) и Части 2 (механика атак, проверка спецэффектов и уязвимостей через if / else и switch).
|
||||||
|
|
||||||
|
Главная цель — полностью отказаться от жесткой привязки к конкретному покемону игрока (Пикачу) и конкретным механикам (бросок монетки). Характеристики покемона игрока считываются динамически, а данные противника жестко задаются в коде. Программа упаковывает процесс дуэли в игровой цикл с обязательным использованием трех видов циклов (for, do-while, while), операторов break / continue и интерактивного считывания данных.
|
||||||
|
## Ключевой код
|
||||||
|
```csharp
|
||||||
|
Console.WriteLine("Приготовьтесь к дуэли!");
|
||||||
|
for (int i = 3; i >= 1; i--)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{i}...");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user