diff --git a/works/lab-04/src/Program.cs b/works/lab-04/src/Program.cs new file mode 100644 index 0000000..1840eba --- /dev/null +++ b/works/lab-04/src/Program.cs @@ -0,0 +1,101 @@ +using System; +using HelpMethods; +using System.Collections.Generic; + +namespace Test +{ + internal class Program + { + static void Main(string[] args) + { + Action1(); + SystemHelp.Waiting(true); + + + + var backpack = CreateBackpack(); + FillBackpack(backpack); + ShowItemsInBackpack(backpack); + + UseItem(backpack); + ShowItemsInBackpack(backpack); + + SystemHelp.Waiting(true); + } + + /// + /// Методы для задания №1. + /// + static void Action1() => ShowCommand(CommandRegistration()); + static string[] CommandRegistration() + { + const byte COUNT = 3; + var pokemons = new string[COUNT]; + + Console.WriteLine("=== Command registration ==="); + for (byte pokemon = 0; pokemon < COUNT; pokemon++) + { + Console.Write($"Pokemon №{pokemon + 1}: "); + pokemons[pokemon] = Console.ReadLine() ?? $"Pokemon{pokemon + 1}"; + + if(pokemons[pokemon] == String.Empty) + pokemons[pokemon] = $"Pokemon{pokemon + 1}"; + } + StringHelp.Br(); + + return pokemons; + } + static void ShowCommand(string[] pokemons) + { + byte counter = 1; + + Console.WriteLine("=== Your command ==="); + foreach(var pokemon in pokemons) + Console.WriteLine($"{counter++}. {pokemon}"); + } + + /// + /// Методы для задания №2. + /// + static List CreateBackpack() => new List(); + static void FillBackpack(List backpack) + { + string[] initialItems = + { + "Зелье HP", + "Покебол", + "Антидот", + }; + + foreach (var item in initialItems) + backpack.Add(item); + + Console.WriteLine("The backpack was filled!\n"); + } + static void ShowItemsInBackpack(List backpack) + { + byte counter = 1; + + Console.WriteLine("=== Items ==="); + foreach(var item in backpack) + Console.WriteLine($"{counter++}. {item}"); + + Console.WriteLine($"\nItems in the backpack: {backpack.Count}\n"); + } + static void UseItem(List backpack) + { + Console.Write("What item do you want to use?\nItem: "); + string targetItem = Console.ReadLine().Trim(); + StringHelp.Br(); + + if(!backpack.Exists(item => item == targetItem)) + { + Console.WriteLine($"The item \"{targetItem}\" was not foumd.\n"); + return; + } + + backpack.Remove(targetItem); + Console.WriteLine($"You use {targetItem}!\n"); + } + } +} \ No newline at end of file diff --git a/works/lab-04/src/Test.csproj b/works/lab-04/src/Test.csproj new file mode 100644 index 0000000..81f2966 --- /dev/null +++ b/works/lab-04/src/Test.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {0580ACC5-9C57-48B6-A97B-75103119F024} + Exe + Test + Test + v4.8 + latest + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + .\MyDll.dll + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/works/lab-04/src/lib/MyDll.dll b/works/lab-04/src/lib/MyDll.dll new file mode 100644 index 0000000..26eb050 Binary files /dev/null and b/works/lab-04/src/lib/MyDll.dll differ diff --git a/works/lab-05/src/Program.cs b/works/lab-05/src/Program.cs new file mode 100644 index 0000000..335314b --- /dev/null +++ b/works/lab-05/src/Program.cs @@ -0,0 +1,77 @@ +using System; +using HelpMethods; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +namespace Test +{ + internal class Program + { + static Random rand = new Random(); + static void Main(string[] args) + { + short pokemonHp = 20; + string pokemon; + byte pokemonLevel; + double difficulty = 1.5; + + + Console.WriteLine($"Hp befor: {pokemonHp} HP\n"); + HealPokemon(ref pokemonHp); + Console.WriteLine($"Hp after: {pokemonHp} HP\n"); + + + SearchBushes(out pokemon, out pokemonLevel); + + RegisterTournament(difficulty, "p1", "p2"); + RegisterTournament(difficulty, "p1", "p2", "p3", "p4"); + } + + /// + /// Метод для задания №1. + /// + static void HealPokemon(ref short hp) + { + Console.WriteLine("Healed!"); + hp += 80; + } + + /// + /// Метод для задания №2. + /// + static void SearchBushes(out string foundPokemon, out byte pokemonLevel) + { + string[] wildPokemons = + { + "Pokemon1", + "Pokemon2", + "Pokemon3", + "Pokemon4", + "Пикачу", + }; + + foundPokemon = wildPokemons[rand.Next(wildPokemons.Length)]; + pokemonLevel = (byte)rand.Next(1, 16); + + Console.WriteLine( +$@"=== ИССЛЕДОВАНИЕ ЛОКАЦИИ === +Вы зашли в высокую траву... +Шорох! Из кустов появляется дикий {foundPokemon} (Уровень: {pokemonLevel})! +"); + } + + /// + /// Метод для задания №3. + /// + static void RegisterTournament(in double difficulty, params string[] participants) + { + byte counter = 1; + + Console.WriteLine($"=== Registered Pokemons ===\nDifficulty: {difficulty}"); + foreach(string participant in participants) + Console.WriteLine($"Pkemon №{counter++}: {participant}"); + + StringHelp.Br(); + } + } +} \ No newline at end of file diff --git a/works/lab-05/src/Test.csproj b/works/lab-05/src/Test.csproj new file mode 100644 index 0000000..81f2966 --- /dev/null +++ b/works/lab-05/src/Test.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {0580ACC5-9C57-48B6-A97B-75103119F024} + Exe + Test + Test + v4.8 + latest + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + .\MyDll.dll + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/works/lab-05/src/lib/MyDll.dll b/works/lab-05/src/lib/MyDll.dll new file mode 100644 index 0000000..26eb050 Binary files /dev/null and b/works/lab-05/src/lib/MyDll.dll differ