generated from admin/template
new
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace lab5
|
||||||
|
{
|
||||||
|
class lab5
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
|
||||||
|
{
|
||||||
|
Console.WriteLine("Задание 1. Лечение в Покецентре (Использование ref)");
|
||||||
|
Console.WriteLine("=== ПОКЕЦЕНТР: ЛЕЧЕНИЕ ===");
|
||||||
|
int pokemonHP = 20;
|
||||||
|
Console.WriteLine($"Здоровье до лечения: {pokemonHP} HP");
|
||||||
|
static void HealPokemon(ref int myPokemonHP)
|
||||||
|
|
||||||
|
{
|
||||||
|
myPokemonHP+= 80;
|
||||||
|
Console.WriteLine($"[Покецентр] Покемон полностью здоров! Восстановлено 80 HP.");
|
||||||
|
}
|
||||||
|
|
||||||
|
HealPokemon(ref pokemonHP);
|
||||||
|
Console.WriteLine($"Здоровье после лечения: {pokemonHP} HP");
|
||||||
|
|
||||||
|
Console.WriteLine("\nЗадание 2. Поиск дикого покемона в высокой траве (Использование out)");
|
||||||
|
Console.WriteLine("=== ИССЛЕДОВАНИЕ ЛОКАЦИИ ===");
|
||||||
|
Console.WriteLine("Вы зашли в высокую траву...");
|
||||||
|
static void SearchBushes(out string foundPokemon, out int pokemonLevel)
|
||||||
|
{
|
||||||
|
|
||||||
|
foundPokemon = "Пикачу";
|
||||||
|
Random rnd = new Random();
|
||||||
|
pokemonLevel = rnd.Next(1, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchBushes(out string Pokemon, out int Level);
|
||||||
|
|
||||||
|
Console.WriteLine($"Шорох! Из кустов появляется дикий {Pokemon} (Уровень: {Level})!");
|
||||||
|
Console.WriteLine("=== РЕГИСТРАЦИЯ НА ТУРНИР ===");
|
||||||
|
|
||||||
|
static void RegisterTournament (in double difficulty)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Правила боя: {difficulty}");
|
||||||
|
}
|
||||||
|
|
||||||
|
string currentRules = "Использовать только одного покемона.";
|
||||||
|
PrintArenaRules(in currentRules);
|
||||||
|
static void ShowTeam(params string[] participants)
|
||||||
|
{
|
||||||
|
// pokemons внутри метода работает как обычный массив
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
# Лабораторная работа №5
|
||||||
|
|
||||||
|
* **Студент:** [Пузанова Анна Андреевна]
|
||||||
|
* **Лабораторная работа №5:** [Функции и методы в C#. Возвращаемые значения и модификаторы параметров (ref, out, in, params)]
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Ключевой код
|
||||||
|
```csharp
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace lab5
|
||||||
|
{
|
||||||
|
class lab5
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
|
||||||
|
{
|
||||||
|
Console.WriteLine("Задание 1. Лечение в Покецентре (Использование ref)");
|
||||||
|
Console.WriteLine("=== ПОКЕЦЕНТР: ЛЕЧЕНИЕ ===");
|
||||||
|
int pokemonHP = 20;
|
||||||
|
Console.WriteLine($"Здоровье до лечения: {pokemonHP} HP");
|
||||||
|
static void HealPokemon(ref int myPokemonHP)
|
||||||
|
|
||||||
|
{
|
||||||
|
myPokemonHP+= 80;
|
||||||
|
Console.WriteLine($"[Покецентр] Покемон полностью здоров! Восстановлено 80 HP.");
|
||||||
|
}
|
||||||
|
|
||||||
|
HealPokemon(ref pokemonHP);
|
||||||
|
Console.WriteLine($"Здоровье после лечения: {pokemonHP} HP");
|
||||||
|
|
||||||
|
Console.WriteLine("\nЗадание 2. Поиск дикого покемона в высокой траве (Использование out)");
|
||||||
|
Console.WriteLine("=== ИССЛЕДОВАНИЕ ЛОКАЦИИ ===");
|
||||||
|
Console.WriteLine("Вы зашли в высокую траву...");
|
||||||
|
static void SearchBushes(out string foundPokemon, out int pokemonLevel)
|
||||||
|
{
|
||||||
|
|
||||||
|
foundPokemon = "Пикачу";
|
||||||
|
Random rnd = new Random();
|
||||||
|
pokemonLevel = rnd.Next(1, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchBushes(out string Pokemon, out int Level);
|
||||||
|
|
||||||
|
Console.WriteLine($"Шорох! Из кустов появляется дикий {Pokemon} (Уровень: {Level})!");
|
||||||
|
Console.WriteLine("=== РЕГИСТРАЦИЯ НА ТУРНИР ===");
|
||||||
|
|
||||||
|
static void RegisterTournament (in double difficulty)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Правила боя: {difficulty}");
|
||||||
|
}
|
||||||
|
|
||||||
|
string currentRules = "Использовать только одного покемона.";
|
||||||
|
PrintArenaRules(in currentRules);
|
||||||
|
static void ShowTeam(params string[] participants)
|
||||||
|
{
|
||||||
|
// pokemons внутри метода работает как обычный массив
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ВЫВОД:
|
||||||
|
|
||||||
|
Задание 1. Лечение в Покецентре (Использование ref)
|
||||||
|
=== ПОКЕЦЕНТР: ЛЕЧЕНИЕ ===
|
||||||
|
Здоровье до лечения: 20 HP
|
||||||
|
[Покецентр] Покемон полностью здоров! Восстановлено 80 HP.
|
||||||
|
Здоровье после лечения: 100 HP
|
||||||
|
|
||||||
|
Задание 2. Поиск дикого покемона в высокой траве (Использование out)
|
||||||
|
=== ИССЛЕДОВАНИЕ ЛОКАЦИИ ===
|
||||||
|
Вы зашли в высокую траву...
|
||||||
|
Шорох! Из кустов появляется дикий Пикачу (Уровень: 6)!
|
||||||
|
|
||||||
|
Process finished with exit code 0.
|
||||||
@@ -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", "{993468BA-62CE-4D90-8D33-0F4853957FC1}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{993468BA-62CE-4D90-8D33-0F4853957FC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{993468BA-62CE-4D90-8D33-0F4853957FC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{993468BA-62CE-4D90-8D33-0F4853957FC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{993468BA-62CE-4D90-8D33-0F4853957FC1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user