generated from admin/template
complete lab-05, start stage-05
This commit is contained in:
@@ -7,8 +7,10 @@
|
||||
* [Лабораторная работа №2](./works/lab-02)
|
||||
* [Лабораторная работа №3](./works/lab-03)
|
||||
* [Лабораторная работа №4](./works/lab-04)
|
||||
* [Лабораторная работа №5](./works/lab-05)
|
||||
|
||||
* [Стадия №1](./works/stage-01)
|
||||
* [Стадия №2](./works/stage-02)
|
||||
* [Стадия №3](./works/stage-03)
|
||||
* [Стадия №4](./works/stage-04)
|
||||
* [Стадия №4](./works/stage-04)
|
||||
* [Стадия №5](./works/stage-05)
|
||||
@@ -0,0 +1,56 @@
|
||||
# Лабораторная работа №5
|
||||
|
||||
* **Студент:** Прибыткова Елизавета Дмитриевна
|
||||
* **Тема:** [Функции и методы в C#. Возвращаемые значения и модификаторы параметров (ref, out, in, params)]
|
||||
|
||||
---
|
||||
|
||||
## Ключевой код
|
||||
```csharp
|
||||
|
||||
int pokemonHP = 20;
|
||||
Console.WriteLine("=== ПОКЕЦЕНТР: ЛЕЧЕНИЕ ===");
|
||||
Console.WriteLine($"Здоровье до лечения: {pokemonHP} HP.");
|
||||
HealPokemon(ref pokemonHP);
|
||||
Console.WriteLine($"Здоровье после лечения: {pokemonHP} HP.");
|
||||
|
||||
Console.WriteLine("\n=== ИССЛЕДОВАНИЕ ЛОКАЦИИ ===");
|
||||
Console.WriteLine("Вы зашли в высокую траву...");
|
||||
SearchBushes(out string foundPokemon, out int pokemonLevel);
|
||||
Console.WriteLine($"Шорох! Из кустов появляется дикий {foundPokemon} (Уровень: {pokemonLevel})!");
|
||||
|
||||
Console.WriteLine("\n=== РЕГИСТРАЦИЯ НА ТУРНИР ===");
|
||||
double difficulty = 1.5;
|
||||
RegisterTournament(difficulty, "Булбазавр", "Чармандер" );
|
||||
Console.WriteLine("-----------------------------");
|
||||
RegisterTournament(difficulty, "Сквиртл", "Пикачу", "Псайдак", "Мяут" );
|
||||
Console.WriteLine("=============================");
|
||||
|
||||
void HealPokemon(ref int pokemonHP)
|
||||
{
|
||||
if (pokemonHP >= 100)
|
||||
return;
|
||||
pokemonHP += 80;
|
||||
if (pokemonHP > 100)
|
||||
pokemonHP = 100;
|
||||
Console.WriteLine("[Покецентр] Покемон полностью здоров! Восстановлено 80 HP.");
|
||||
}
|
||||
|
||||
void SearchBushes(out string foundPokemon, out int pokemonLevel)
|
||||
{
|
||||
foundPokemon = "Пикачу";
|
||||
pokemonLevel = new Random().Next(1, 15);
|
||||
}
|
||||
|
||||
void RegisterTournament(in double difficulty, params string[] participants)
|
||||
{
|
||||
//difficulty = 3;
|
||||
Console.WriteLine($"Коэффициент стадиона: {difficulty}");
|
||||
foreach (var pokemon in participants )
|
||||
{
|
||||
Console.WriteLine($"* {pokemon}");
|
||||
}
|
||||
}
|
||||
```
|
||||
---
|
||||

|
||||
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
@@ -0,0 +1,44 @@
|
||||
|
||||
int pokemonHP = 20;
|
||||
Console.WriteLine("=== ПОКЕЦЕНТР: ЛЕЧЕНИЕ ===");
|
||||
Console.WriteLine($"Здоровье до лечения: {pokemonHP} HP.");
|
||||
HealPokemon(ref pokemonHP);
|
||||
Console.WriteLine($"Здоровье после лечения: {pokemonHP} HP.");
|
||||
|
||||
Console.WriteLine("\n=== ИССЛЕДОВАНИЕ ЛОКАЦИИ ===");
|
||||
Console.WriteLine("Вы зашли в высокую траву...");
|
||||
SearchBushes(out string foundPokemon, out int pokemonLevel);
|
||||
Console.WriteLine($"Шорох! Из кустов появляется дикий {foundPokemon} (Уровень: {pokemonLevel})!");
|
||||
|
||||
Console.WriteLine("\n=== РЕГИСТРАЦИЯ НА ТУРНИР ===");
|
||||
double difficulty = 1.5;
|
||||
RegisterTournament(difficulty, "Булбазавр", "Чармандер" );
|
||||
Console.WriteLine("-----------------------------");
|
||||
RegisterTournament(difficulty, "Сквиртл", "Пикачу", "Псайдак", "Мяут" );
|
||||
Console.WriteLine("=============================");
|
||||
|
||||
void HealPokemon(ref int pokemonHP)
|
||||
{
|
||||
if (pokemonHP >= 100)
|
||||
return;
|
||||
pokemonHP += 80;
|
||||
if (pokemonHP > 100)
|
||||
pokemonHP = 100;
|
||||
Console.WriteLine("[Покецентр] Покемон полностью здоров! Восстановлено 80 HP.");
|
||||
}
|
||||
|
||||
void SearchBushes(out string foundPokemon, out int pokemonLevel)
|
||||
{
|
||||
foundPokemon = "Пикачу";
|
||||
pokemonLevel = new Random().Next(1, 15);
|
||||
}
|
||||
|
||||
void RegisterTournament(in double difficulty, params string[] participants)
|
||||
{
|
||||
//difficulty = 3;
|
||||
Console.WriteLine($"Коэффициент стадиона: {difficulty}");
|
||||
foreach (var pokemon in participants )
|
||||
{
|
||||
Console.WriteLine($"* {pokemon}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RootNamespace>lab_05</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lab-05", "lab-05.csproj", "{D73CF250-78BC-4A3A-A9C4-679C3BBA1CC0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D73CF250-78BC-4A3A-A9C4-679C3BBA1CC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D73CF250-78BC-4A3A-A9C4-679C3BBA1CC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D73CF250-78BC-4A3A-A9C4-679C3BBA1CC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D73CF250-78BC-4A3A-A9C4-679C3BBA1CC0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,231 @@
|
||||
# Stage №5
|
||||
|
||||
* **Студент:** Прибыткова Елизавета Дмитриевна
|
||||
* **Техническое задание:** Турнир Лиги Покемонов (Глобальный игровой цикл с коллекциями)
|
||||
|
||||
---
|
||||
|
||||
## Ключевой код
|
||||
```csharp
|
||||
string[] activeTeam = new string[3];
|
||||
List<string> backpack = new List<string>();
|
||||
int[] pokedexHP = new int[3];
|
||||
int[] pokedexDamage = new int[3];
|
||||
|
||||
string[] enemyNames = { "Мяут", "Геодуд", "Гарчомп" };
|
||||
int[] enemyHPs = { 40, 65, 90 };
|
||||
int[] enemyDamages = { 10, 15, 25 };
|
||||
int[] enemyTypes = { 3, 1, 2 };
|
||||
|
||||
int currentEnemyIndex = 0;
|
||||
int activeFighterIndex = 0;
|
||||
int actionChoice, attackChoice;
|
||||
string itemChoice;
|
||||
|
||||
Console.WriteLine("=== РЕГИСТРАЦИЯ НА СЕЗОН ЛИГИ ===");
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Console.Write($"Введите имя покемона №{i + 1}: ");
|
||||
activeTeam[i] = Console.ReadLine();
|
||||
Console.Write($"Введите макс. HP для {activeTeam[i]}: ");
|
||||
pokedexHP[i] = int.Parse(Console.ReadLine());
|
||||
Console.Write($"Введите базовый урон для {activeTeam[i]}: ");
|
||||
pokedexDamage[i] = int.Parse(Console.ReadLine());;
|
||||
Console.WriteLine();
|
||||
}
|
||||
backpack.Add("Зелье HP");
|
||||
backpack.Add("Суперзелье");
|
||||
backpack.Add("Антидот");
|
||||
Console.WriteLine("Вы упаковали походную сумку тренера.");
|
||||
Console.WriteLine("Предметов в инвентаре изначально: " + backpack.Count);
|
||||
Console.ReadLine();
|
||||
Console.Clear();
|
||||
|
||||
Console.WriteLine("Подготовка завершена! Ворота Арены открываются через...");
|
||||
for (int i = 3; i > 0; i--)
|
||||
{
|
||||
Console.WriteLine(i + "...");
|
||||
}
|
||||
Console.WriteLine("======================================================================");
|
||||
Console.WriteLine("=== ТУРНИР НАЧАЛСЯ ===");
|
||||
while (currentEnemyIndex < 3 && (pokedexHP[0] > 0 | pokedexHP[1] > 0 | pokedexHP[2] > 0))
|
||||
{
|
||||
Console.WriteLine($"=== ЭТАП {currentEnemyIndex + 1} ===");
|
||||
Console.WriteLine($"Ваш активный боец: {activeTeam[activeFighterIndex]} (HP: {pokedexHP[activeFighterIndex]}) VS Дикий {enemyNames[currentEnemyIndex]} (HP: {enemyHPs[currentEnemyIndex]})");
|
||||
Console.WriteLine("----------------------------------------------------------------------");
|
||||
while (pokedexHP[activeFighterIndex] > 0 && enemyHPs[currentEnemyIndex] > 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
Console.Write("Выберите действие (1 - Атака, 2 - Сумка, 3 - Смена Покемона): ");
|
||||
actionChoice = int.Parse(Console.ReadLine());
|
||||
} while (actionChoice != 1 && actionChoice != 2 && actionChoice != 3 );
|
||||
|
||||
switch (actionChoice)
|
||||
{
|
||||
case 1:
|
||||
do
|
||||
{
|
||||
Console.Write("Проверка точности (1 - Критический урон, 0 - Обычный): ");
|
||||
attackChoice = int.Parse(Console.ReadLine());
|
||||
} while (attackChoice != 0 && attackChoice != 1);
|
||||
if (attackChoice == 0)
|
||||
{
|
||||
enemyHPs[currentEnemyIndex] -= pokedexDamage[activeFighterIndex];
|
||||
Console.WriteLine($"Результат: Нанесено урона: {pokedexDamage[activeFighterIndex]}");
|
||||
}
|
||||
else
|
||||
{
|
||||
enemyHPs[currentEnemyIndex] -= (pokedexDamage[activeFighterIndex] + 15);
|
||||
Console.WriteLine($"Результат: Критический удар! Нанесено урона: {pokedexDamage[activeFighterIndex] + 15}");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (backpack.Count > 0)
|
||||
{
|
||||
Console.WriteLine("--- Содержимое вашей сумки ---");
|
||||
foreach (var item in backpack)
|
||||
{
|
||||
Console.WriteLine($"[Предмет] -> {item}");
|
||||
}
|
||||
Console.Write("Какой предмет использовать? Введите название: ");
|
||||
itemChoice = Console.ReadLine();
|
||||
switch (itemChoice)
|
||||
{
|
||||
case "Зелье HP":
|
||||
backpack.Remove(itemChoice);
|
||||
Console.WriteLine($"Результат: {activeTeam[activeFighterIndex]} восстановил 30 HP! Предмет удален из сумки.");
|
||||
pokedexHP[activeFighterIndex] += 30;
|
||||
break;
|
||||
case "Суперзелье":
|
||||
backpack.Remove(itemChoice);
|
||||
Console.WriteLine($"Результат: {activeTeam[activeFighterIndex]} восстановил 60 HP! Предмет удален из сумки.");
|
||||
pokedexHP[activeFighterIndex] += 60;
|
||||
break;
|
||||
case "Антидот":
|
||||
backpack.Remove(itemChoice);
|
||||
Console.WriteLine($"Результат: {activeTeam[activeFighterIndex]} выпивает антидот! Предмет удален из сумки.");
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Такого предмета нет в сумке.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
Console.WriteLine("Ваш рюкзак пуст.");
|
||||
break;
|
||||
case 3:
|
||||
Console.WriteLine("--- Ваша команда ---");
|
||||
for (int i = 0; i < activeTeam.Length; i++)
|
||||
{
|
||||
Console.WriteLine($" {i + 1}. {activeTeam[i]} HP: {pokedexHP[i]}");
|
||||
}
|
||||
do
|
||||
{
|
||||
Console.Write("Введите номер замены: ");
|
||||
attackChoice = int.Parse(Console.ReadLine());
|
||||
if (attackChoice >= 1 && attackChoice <= 3 && pokedexHP[attackChoice - 1] <= 0)
|
||||
Console.WriteLine($"{activeTeam[attackChoice - 1]} в нокауте. Выберите другого бойца.");
|
||||
else if (attackChoice < 1 || attackChoice > 3)
|
||||
Console.WriteLine("Неверный номер. Введите число от 1 до 3.");
|
||||
} while (attackChoice < 1 | attackChoice > 3 | pokedexHP[attackChoice - 1] <= 0);
|
||||
if (pokedexHP[attackChoice - 1] > 0)
|
||||
{
|
||||
activeFighterIndex = attackChoice - 1;
|
||||
Console.WriteLine($"Ваш текущий боец: {activeTeam[activeFighterIndex]} (HP: {pokedexHP[activeFighterIndex]})");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (enemyHPs[currentEnemyIndex] <= 0)
|
||||
{
|
||||
enemyHPs[currentEnemyIndex] = 0;
|
||||
Console.WriteLine($"Дикий {enemyNames[currentEnemyIndex]} нокаутирован! Вы переходите на следующий этап!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine($"\nДикий {enemyNames[currentEnemyIndex]} проводит контратаку!");
|
||||
attackChoice = enemyTypes[currentEnemyIndex];
|
||||
switch (attackChoice)
|
||||
{
|
||||
case 1:
|
||||
pokedexHP[activeFighterIndex] -= enemyDamages[currentEnemyIndex] * 2;
|
||||
Console.WriteLine("Расчёт: Боевой тип! Урон удваивается.");
|
||||
Console.WriteLine($"{activeTeam[activeFighterIndex]} получил урон: {enemyDamages[currentEnemyIndex] * 2}");
|
||||
break;
|
||||
case 2:
|
||||
if (enemyDamages[currentEnemyIndex] < 10)
|
||||
{
|
||||
Console.WriteLine($"{activeTeam[activeFighterIndex]} не получает урона!");
|
||||
}
|
||||
else
|
||||
{
|
||||
pokedexHP[activeFighterIndex] -= (enemyDamages[currentEnemyIndex] - 10);
|
||||
Console.WriteLine("Расчёт: Стальной тип! Урон снижается на 10 единиц.");
|
||||
Console.WriteLine($"{activeTeam[activeFighterIndex]} получил урон: {enemyDamages[currentEnemyIndex] - 10}");
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
pokedexHP[activeFighterIndex] -= enemyDamages[currentEnemyIndex];
|
||||
Console.WriteLine("Расчёт: Обычный тип! Урон наносится без изменений.");
|
||||
Console.WriteLine($"{activeTeam[activeFighterIndex]} получил урон: {enemyDamages[currentEnemyIndex]}");
|
||||
break;
|
||||
}
|
||||
if (pokedexHP[activeFighterIndex] <= 0)
|
||||
{
|
||||
pokedexHP[activeFighterIndex] = 0;
|
||||
if((pokedexHP[0] > 0 | pokedexHP[1] > 0 | pokedexHP[2] > 0))
|
||||
{Console.WriteLine($"{activeTeam[activeFighterIndex]} нокаутирован. Выберите другого бойца.");
|
||||
Console.WriteLine("--- Ваша команда ---");
|
||||
for (int i = 0; i < activeTeam.Length; i++)
|
||||
{
|
||||
Console.WriteLine($" {i + 1}. {activeTeam[i]} HP: {pokedexHP[i]}");
|
||||
}
|
||||
do
|
||||
{
|
||||
Console.Write("Введите номер замены: ");
|
||||
attackChoice = int.Parse(Console.ReadLine());
|
||||
if (attackChoice >= 1 && attackChoice <= 3 && pokedexHP[attackChoice - 1] <= 0)
|
||||
Console.WriteLine($"{activeTeam[attackChoice - 1]} в нокауте. Выберите другого бойца.");
|
||||
else if (attackChoice < 1 || attackChoice > 3)
|
||||
Console.WriteLine("Неверный номер. Введите число от 1 до 3.");
|
||||
} while (attackChoice < 1 | attackChoice > 3 | pokedexHP[attackChoice - 1] <= 0);
|
||||
if (pokedexHP[attackChoice - 1] > 0)
|
||||
{
|
||||
activeFighterIndex = attackChoice - 1;
|
||||
Console.WriteLine($"Ваш текущий боец: {activeTeam[activeFighterIndex]} (HP: {pokedexHP[activeFighterIndex]})");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Команда потерпела поражение от {enemyNames[currentEnemyIndex]}. Попробуйте еще раз.");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
Console.WriteLine("----------------------------------------------------------------------");
|
||||
Console.WriteLine($"Текущий статус: {activeTeam[activeFighterIndex]} (HP: {pokedexHP[activeFighterIndex]}) | {enemyNames[currentEnemyIndex]} (HP: {enemyHPs[currentEnemyIndex]})\n");
|
||||
}
|
||||
if (pokedexHP[0] == 0 && pokedexHP[1] == 0 && pokedexHP[2] == 0)
|
||||
break;
|
||||
currentEnemyIndex++;
|
||||
}
|
||||
if((pokedexHP[0] > 0 | pokedexHP[1] > 0 | pokedexHP[2] > 0))
|
||||
{
|
||||
Console.WriteLine("\n======================================================================");
|
||||
Console.WriteLine("=== ТУРНИР ОКОНЧЕН ===");
|
||||
Console.WriteLine("Вы победили всех боссов Лиги и стали Чемпионом!");
|
||||
Console.WriteLine("======================================================================");
|
||||
}
|
||||
```
|
||||
|
||||
** Рис.1 Ввод данных**
|
||||

|
||||
|
||||
** Рис.2 Начало турнира по аналогии с эталоном**
|
||||

|
||||
|
||||
** Рис.3 Завершение турнира**
|
||||

|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 110 KiB |
@@ -0,0 +1,38 @@
|
||||
int dmg = 30;
|
||||
int type = 2;
|
||||
Console.WriteLine(CalculateIncomingDamage(dmg, type));
|
||||
int CalculateIncomingDamage(in int baseDamage, in int attackType)
|
||||
{
|
||||
//baseDamage = 10; Нельзя менять in-параметры. Только для чтения
|
||||
switch (attackType)
|
||||
{
|
||||
case 1:
|
||||
return baseDamage * 2;
|
||||
case 2:
|
||||
if (baseDamage <= 20)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
return baseDamage - 20;
|
||||
}
|
||||
case 3:
|
||||
return baseDamage;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UseHealPotion(ref int pokemonHP, List<string> bag, out int itemsLeft)
|
||||
{
|
||||
|
||||
itemsLeft = bag.Count;
|
||||
}
|
||||
|
||||
void LogRoundEvents(params string[] events)
|
||||
{
|
||||
Console.WriteLine("\n--- ЛОГ ТЕКУЩЕГО РАУНДА ---");
|
||||
foreach (var incident in events)
|
||||
{
|
||||
Console.WriteLine($"[Бой]: {incident}");
|
||||
}
|
||||
Console.WriteLine("--------------------------");
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RootNamespace>stage_05</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "stage-05", "stage-05.csproj", "{83F4DA8C-69EC-4BEC-9E06-573274797A6A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{83F4DA8C-69EC-4BEC-9E06-573274797A6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{83F4DA8C-69EC-4BEC-9E06-573274797A6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{83F4DA8C-69EC-4BEC-9E06-573274797A6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{83F4DA8C-69EC-4BEC-9E06-573274797A6A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Reference in New Issue
Block a user