From c9ae1f127a071c4df818fb53d6b3f821e29a5001 Mon Sep 17 00:00:00 2001 From: Vizard Date: Sun, 27 Sep 2026 00:42:21 +0300 Subject: [PATCH] lab-03 done --- works/lab-03/src/Program.cs | 385 ++++++++++++++++----------------- works/lab-03/src/Test.csproj | 58 +++++ works/lab-03/src/lib/MyDll.dll | Bin 0 -> 5120 bytes 3 files changed, 247 insertions(+), 196 deletions(-) create mode 100644 works/lab-03/src/Test.csproj create mode 100644 works/lab-03/src/lib/MyDll.dll diff --git a/works/lab-03/src/Program.cs b/works/lab-03/src/Program.cs index 4c9d49f..090426c 100644 --- a/works/lab-03/src/Program.cs +++ b/works/lab-03/src/Program.cs @@ -1,201 +1,194 @@ -//==================== Main -//============================================== -IsReady(); -//==================== System fun -//============================================== -static void PrintError(Exception e) -{ - //Console.BackgroundColor = ConsoleColor.Gray; - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"Error: {e.Message}"); - Console.ResetColor(); +using System; +using HelpMethods; - Console.WriteLine("Press any key to continue...\n"); - Console.ReadKey(); - Console.Clear(); -} -static void ShowTask(byte number, bool isStart = false) +namespace Test { - if (isStart == false) + internal class Program { - Console.WriteLine("\nPress any key to continue..."); - Console.ReadKey(); + static void Main(string[] args) + { + byte roundNumber; + + short + pokemon1Hp, + pokemon2Hp, + pokemon1Attack, + pokemon2Attack; + + string + pokemon1Name, + pokemon2Name; + + Battle(out pokemon1Hp, + out pokemon2Hp, + out pokemon1Attack, + out pokemon2Attack, + out roundNumber, + out pokemon1Name, + out pokemon2Name); + } + + /// + /// Метод для задания №3. + /// + static void Battle(out short pokemon1Hp, + out short pokemon2Hp, + out short pokemon1Attack, + out short pokemon2Attack, + out byte roundNumber, + out string pokemon1Name, + out string pokemon2Name, + byte startType = 0) + { + pokemon1Hp = 0; + pokemon2Hp = 0; + pokemon1Attack = 0; + pokemon2Attack = 0; + roundNumber = 0; + + pokemon1Name = string.Empty; + pokemon2Name = string.Empty; + + if (startType == 0) + SetSeedData(out pokemon1Hp, + out pokemon2Hp, + out pokemon1Attack, + out pokemon2Attack, + out roundNumber, + out pokemon1Name, + out pokemon2Name); + // else: methods for initialization + + if (!ReadyQuestion(pokemon1Hp, + pokemon2Hp, + pokemon1Attack, + pokemon2Attack, + pokemon1Name, + pokemon2Name)) + return; + + string + WIN_P1 = $"Winner: {pokemon1Name}!", + WIN_P2 = $"Winner: {pokemon2Name}!", + BATTLE_END = "=== The end of the battle ===\n"; + + while (true) + { + Console.WriteLine($"=== Round №{roundNumber} ==="); + + if (roundNumber % 2 == 1) + { + Console.WriteLine($"{pokemon1Name} наносит {pokemon1Attack} урона по {pokemon2Name}!"); + pokemon2Hp -= pokemon1Attack; + if (pokemon2Hp < 0) pokemon2Hp = 0; + } + else + { + Console.WriteLine($"{pokemon2Name} наносит {pokemon2Attack} урона по {pokemon1Name}!"); + pokemon1Hp -= pokemon2Attack; + if (pokemon1Hp < 0) pokemon1Hp = 0; + } + + Console.WriteLine($"The round result: {pokemon1Name} HP: {pokemon1Hp} | {pokemon2Name} HP: {pokemon2Hp}\n"); + roundNumber++; + + if (pokemon2Hp < 1) + { + Console.WriteLine(BATTLE_END + WIN_P1); + return; + } + if (pokemon1Hp < 1) + { + Console.WriteLine(BATTLE_END + WIN_P2); + return; + } + } + } + + /// + /// Метод для задания №1. + /// + static void StartBattle(short pokemon1Hp, + short pokemon2Hp, + short pokemon1Attack, + short pokemon2Attack, + string pokemon1Name, + string pokemon2Name) + { + string message = +$@"=== The battle begins === +{pokemon1Name} (HP: {pokemon1Hp} | Attack: {pokemon1Attack}) VS {pokemon2Name} (HP: {pokemon2Hp} | Attack: {pokemon2Attack}) +"; + + TimeHelp.ShowTimer("Ready!"); + Console.WriteLine(message); + } + + /// + /// Метод для задания №2. + /// + static bool ReadyQuestion(short pokemon1Hp, + short pokemon2Hp, + short pokemon1Attack, + short pokemon2Attack, + string pokemon1Name, + string pokemon2Name) + { + if (SetValue() == 1) + { + StartBattle(pokemon1Hp, + pokemon2Hp, + pokemon1Attack, + pokemon2Attack, + pokemon1Name, + pokemon2Name); + return true; + } + + Console.WriteLine("You canceled the battle!"); + return false; + } + + static byte SetValue() + { + const string + MESSAGE = "You are ready to start the battle?\t[1 - \"Yes\" | 0 - \"No\"]\n[Player]: ", + ERROR = $"The value must be equal to 1 or 0"; + + while (true) + { + try + { + Console.Write(MESSAGE); + byte value = byte.Parse(Console.ReadLine()); + + if (value != 0 && value != 1) + throw new Exception(ERROR); + + Console.Clear(); + + return value; + } + catch (Exception e) { SystemHelp.PrintError(e); } + } + } + + static void SetSeedData(out short pokemon1Hp, + out short pokemon2Hp, + out short pokemon1Attack, + out short pokemon2Attack, + out byte roundNumber, + out string pokemon1Name, + out string pokemon2Name) + { + pokemon1Hp = 50; + pokemon2Hp = 55; + pokemon1Attack = 12; + pokemon2Attack = 10; + roundNumber = 1; + + pokemon1Name = "Пикачу"; + pokemon2Name = "Булбазавр"; + } } - Console.Clear(); - Console.WriteLine($"Task №{number}"); -} -static void Br(byte counter = 1) -{ - for (byte i = 0; i < counter; i++) - Console.WriteLine(); -} - - - -// ==================== Modul1 fun -// ============================================== -static void StartFight() -{ - string - pokemonName1 - ,pokemonName2; - - short - hp1 - ,hp2 - ,attack1 - ,attack2; - - InputParams(out pokemonName1, out hp1, out attack1, out pokemonName2, out hp2, out attack2); - ShowTimeCounting(); - GetPokemonInfo(pokemonName1, hp1, attack1, pokemonName2, hp2, attack2); -} -static void ShowTimeCounting() -{ - const byte counter = 3; - const short ticks = 1000; - - Console.WriteLine("Ready!"); - for (byte i = 1; i <= counter; Console.Write($"\r{i++}...")) - Thread.Sleep(ticks); - - Br(2); - Console.WriteLine("=== THE FIGHT BEGINS ==="); - -} -static void GetPokemonInfo(string pokemonName1, short hp1, short attack1, string pokemonName2, short hp2, short attack2) -{ - Console.WriteLine($"{pokemonName1} (HP: {hp1} | Attack: {attack1}) VS {pokemonName2} (HP: {hp2} | Attack: {attack2})"); -} -static void InputParams(out string pokemonName1, out short hp1, out short attack1, out string pokemonName2, - out short hp2, out short attack2) -{ - const short - maxHp = 2000 - ,maxAttack = 500 - ,minHp = 0 - ,minAttack = 1; - - - - Console.Write("Enter Pokemon name for player one!\nName1: "); - pokemonName1 = Console.ReadLine() ?? "Player1"; - - if (pokemonName1 == string.Empty) - pokemonName1 = "Player1"; - - while (true) - { - try - { - - Console.Write("\nEnter the attack power for Pokemon1!\nAttack: "); - attack1 = short.Parse(Console.ReadLine()); - - if (attack1 < minAttack || attack1 > maxAttack) - throw new Exception($"The attack can be between {minAttack} and {maxAttack}."); - - break; - } - catch (Exception e) {PrintError(e);} - } - - while (true) - { - try - { - Console.Write("\nEnter the number of hp for Pokemon1!\nHP: "); - hp1 = short.Parse(Console.ReadLine()); - - if (hp1 < minHp || hp1 > maxHp) - throw new Exception($"The hp can be between {minHp} and {maxHp}."); - - break; - } - catch (Exception e) {PrintError(e);} - } - - - Console.Clear(); - - - Console.Write("Enter Pokemon name for player two!\nName2: "); - pokemonName2 = Console.ReadLine() ?? "Player2"; - - if (pokemonName2 == string.Empty) - pokemonName2 = "Player2"; - - while (true) - { - try - { - Console.Write("\nEnter the attack power for Pokemon2!\nAttack: "); - attack2 = short.Parse(Console.ReadLine()); - - if (attack2 < minAttack || attack2 > maxAttack) - throw new Exception($"The attack can be between {minAttack} and {maxAttack}."); - - break; - } - catch (Exception e) {PrintError(e);} - } - - while (true) - { - try - { - Console.Write("\nEnter the number of hp for Pokemon2!\nHP: "); - hp2 = short.Parse(Console.ReadLine()); - - if (hp2 < minHp || hp2 > maxHp) - throw new Exception($"The hp can be between {minHp} and {maxHp}."); - - break; - } - catch (Exception e) {PrintError(e);} - } - - - Console.Clear(); -} - - - -// ==================== Modul2 fun -// ============================================== -static void IsReady() -{ - if (IsCorrect()) - { - StartFight(); - return; - } - - Console.WriteLine("Are you giving up!"); -} -static bool IsCorrect() -{ - const byte - fixValue1 = 0 - ,fixValue2 = 1; - - do - { - try - { - Console.Write("You are ready to start?\t[1 - Yes | 0 - No]\n[Player]: "); - byte isReady = byte.Parse(Console.ReadLine()); - - if (isReady != fixValue1 && isReady != fixValue2) - throw new Exception($"Incorrect input. Value must be {fixValue1} or {fixValue2}."); - - Console.Clear(); - - if (isReady == fixValue1) - return false; - - return true; - } - catch (Exception e) {PrintError(e);} - } while (true); } \ No newline at end of file diff --git a/works/lab-03/src/Test.csproj b/works/lab-03/src/Test.csproj new file mode 100644 index 0000000..81f2966 --- /dev/null +++ b/works/lab-03/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-03/src/lib/MyDll.dll b/works/lab-03/src/lib/MyDll.dll new file mode 100644 index 0000000000000000000000000000000000000000..ac64f90711528de5b7115fa9772512ecad585be5 GIT binary patch literal 5120 zcmeHLe`p)m9sk~)B-^s1*l`mlX}VnEBq+5laJxZ!O6_-*+cV zu|r2;3<`Va`@Zk*_kG{@-uIq7{ruNSBcc%A`}c|7MbB+S!cPWQAdc<)S&V+%c5BzW z%G9l0^Gl|yR~@_L7-hX+R4TTo=Y{SpS9G(YXHI1GvRxF34I83+0@t(SL{o}J+1AD1 z)kph~cI)j*lBffmh|j&)hhE1!f|saM;;J7vGXgcDDxJJF zjEoSS;Y6%$i+&j2c${c>t?ZL%ov5`*-U|9y6P@tHiU<1Tb^yraT!Xkl$)*!6CLGr( zfReF|0O5s-;caRoh(6&6%Z4JSj27{-uT6NH+6d8D6DiTtoL4lCO{Flsvy1310#_vW z(}V7$O50!t`!3oN?Q4&3B#Kg`=gbGuh{Rm8l6UuFuO?II}q9Dz@*wq zs*Tl(YWLJF_muXQ{*cjTz8w*@&Bm;v-JwmPcsG#vBP?p`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