From e480b87d9ade2bbe36dad4829f777c9dedfa1346 Mon Sep 17 00:00:00 2001 From: Vizard Date: Wed, 23 Sep 2026 23:25:59 +0300 Subject: [PATCH] lab-02 done. --- works/lab-02/MyDll.dll | Bin 0 -> 5120 bytes works/lab-02/Program.cs | 240 +++++++++++++++++++++++++++++++++++++++ works/lab-02/Test.csproj | 58 ++++++++++ 3 files changed, 298 insertions(+) create mode 100644 works/lab-02/MyDll.dll create mode 100644 works/lab-02/Program.cs create mode 100644 works/lab-02/Test.csproj diff --git a/works/lab-02/MyDll.dll b/works/lab-02/MyDll.dll new file mode 100644 index 0000000000000000000000000000000000000000..bfc7e449ca8d2ea592ff7a96508c38ed4d04968b GIT binary patch literal 5120 zcmeHLU2Ggz6+UpKyB~ZiK*?lUdM5QrDS&ZdOgkT z%ywqB%~n+uiU3vc&`MQM5HEm`Qt?tD1ObHye%?xjK!^tfQl;>~OF?RRh^pZ5ojbGM zwG$Op;(}IPrixe+0FTcN8yCmuhQ)-^>Wrh^~VGpG$-;f0b4FuUUsAvrrx! zCOXTFQKBUd#O882aH9&nk%eJ=TZ7HKf<1M6W4s%>l*f))0ba_AG1ILBp zethUjYqSU5(7&5@Ci*-3wh<*LzH8|ZiMX~F?Q9!-kB96@N9a6ixYu@luL{D^kw66z^zQRB;kes zfj1n(FN-ePr`^=X&v5JWNC8VC$Y|MXPf1vqmQNvui zx&(D10D@k@+%)1%w-QSL5G1|m>1)5g<}e*6h5o) zf+~dMev{r71He6zH1Gp$n7&JIi4nB_t(~IRX+oQ%SE&b?hxMm{ zE80F_cjQ^%3AAH)F2U~|3ipsfDe9z`fIajT;AiN2z+Uyx3*!{M-dGKeAeX-)TAYv?Wf31rSWeA2rJ5zbKozg(xRzO< zvh**_NY69MlCqBNIhLgJuIbBZ)0T9)W|qc$Z2Usamz0x*TDfc#EZO8`oywx=nHzXx zo+m2>tG;0Rt*Yy6*C@$~;a+K4Suk8UGKm99zUZ_H8hs{BOD;;+Gab9xt09EnD`vUo z8v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JsNWw!YPnme~B`qJvjKNz^ i`Cfo$d=CG&evNhhMAUllKZAu6p9pV1b@G24f&T#Mc-Dmg literal 0 HcmV?d00001 diff --git a/works/lab-02/Program.cs b/works/lab-02/Program.cs new file mode 100644 index 0000000..45daf34 --- /dev/null +++ b/works/lab-02/Program.cs @@ -0,0 +1,240 @@ +using System; +using HelpMethods; + +namespace Test +{ + internal class Program + { + static void Main(string[] args) + { + short initialBalance = 1500; + + PokemonLeveling(); + BuyPotion(initialBalance); + ShowCondition(); + TUI(); + } + + /// + /// Метод для задания №1. + /// + static void PokemonLeveling() + { + const sbyte MARGIN_1 = -16; + + short pokemonAttack = SetPokemonAttack(); + byte ernedLevels = LevelsRequest(); + + string message = +$@"=== Pokemon leveling === +{"Initial attack:",MARGIN_1}{pokemonAttack} +{"Earned levels:",MARGIN_1}{ernedLevels} + +Final attack: {pokemonAttack + ernedLevels * 5} +------------------------ +"; + + Console.WriteLine(message); + SystemHelp.Waiting(true); + + + static short SetPokemonAttack() + { + const short + MAX_ATTACK = 250 + , MIN_ATTACK = 1; + + string ERROR = $"The attack power must be between {MIN_ATTACK} and {MAX_ATTACK}."; + + while (true) + { + try + { + Console.Write("Set the attack strength.\nAttack strength: "); + short attack = short.Parse(Console.ReadLine()); + + if (attack < MIN_ATTACK || attack > MAX_ATTACK) + throw new Exception(ERROR); + + Console.Clear(); + + return attack; + } + catch (Exception e) { SystemHelp.PrintError(e); } + } + } + static byte LevelsRequest() + { + const short MAX_COUNT = 5; + + string ERROR = $"The number of levels cannot exceed {MAX_COUNT}."; + + while (true) + { + try + { + Console.Write("How many levels have been earned?\nCount: "); + byte lvl = byte.Parse(Console.ReadLine()); + + if (lvl > MAX_COUNT) + throw new Exception(ERROR); + + Console.Clear(); + + return lvl; + } + catch (Exception e) { SystemHelp.PrintError(e); } + } + } + } + + /// + /// Метод для задания №2. + /// + /// + static void BuyPotion(short balance) + { + const byte COST_POTION = 200; + + byte countPotions = GetCountPotions(balance, COST_POTION); + PrintCheque(balance, countPotions, COST_POTION); + SystemHelp.Waiting(true); + + + static byte GetCountPotions(short balance, byte costPotion) + { + const string ERROR = "The purchase amount cannot exceed your balance."; + string message = $"Your balance: {balance}\nHow many potions do you want to buy?\nCount: "; + + while (true) + { + try + { + Console.Write(message); + byte count = byte.Parse(Console.ReadLine()); + + if (balance - costPotion * count < 0) + throw new Exception(ERROR); + + return count; + } + catch (Exception e) { SystemHelp.PrintError(e); } + } + } + static short PrintCheque(short balance, byte countPotions, byte costPotion) + { + const sbyte MARGIN_1 = -10; + + string cheque = +$@" +====== Cheque ====== +{"Balance:",MARGIN_1}{balance} +{"Purchase:",MARGIN_1}{costPotion} X{countPotions} +Amount to be paid:{costPotion * countPotions} + +Remains:{balance - costPotion * countPotions} +--------------------- + +"; + + Console.Write(cheque); + + return (short)(balance - costPotion * countPotions); + } + } + + /// + /// Метод для задания №3. + /// + static void ShowCondition() + { + const string + MESSAGE_1 = "Pokemon lost consciousness!" + , MESSAGE_2 = "The Pokemon is in critical condition!" + , MESSAGE_3 = "The Pokemon is wounded!" + , MESSAGE_4 = "The Pokemon has full HP!"; + + short pokemonHp = GetPokemonHp(); + + if (pokemonHp == 0) + Console.WriteLine(MESSAGE_1); + else if (pokemonHp < 21) + Console.WriteLine(MESSAGE_2); + else if (pokemonHp < 51) + Console.WriteLine(MESSAGE_3); + else + Console.WriteLine(MESSAGE_4); + + StringHelp.Br(); + + SystemHelp.Waiting(true); + + static short GetPokemonHp() + { + const short + MIN_HP = 0 + , MAX_HP = 5000; + + string ERROR = $"Hp should be between {MIN_HP} and {MAX_HP}"; + + while (true) + { + try + { + Console.Write("Enter the number of HP.\nHP: "); + short hp = short.Parse(Console.ReadLine()); + + if (hp MAX_HP) + throw new Exception(ERROR); + + return hp; + } + catch (Exception e) { SystemHelp.PrintError(e); } + } + } + } + + /// + /// Метод для задания №4. + /// + static void TUI() + { + const string hotBar = +@" +====== Actions ====== +Attack [1] +Backpack [2] +Change the Pokemon [3] +Escape [4] +----------------------- + +"; + + Console.Write(hotBar); + + ModuleAction(Console.ReadLine() ?? String.Empty); + + StringHelp.Br(); + + static void ModuleAction(string action) + { + const string + ACTION_1 = "The Pokemon delivers a quick strike!" + , ACTION_2 = "You open the backpack!" + , ACTION_3 = "You choose other Pokemon!" + , ACTION_4 = "You escape!" + , DEFAULT_ACTION = "You didn’t do anything!"; + + + switch (action) + { + case "1": Console.WriteLine(ACTION_1); break; + case "2": Console.WriteLine(ACTION_2); break; + case "3": Console.WriteLine(ACTION_3); break; + case "4": Console.WriteLine(ACTION_4); break; + default: Console.WriteLine(DEFAULT_ACTION); break; + } + } + } + } +} \ No newline at end of file diff --git a/works/lab-02/Test.csproj b/works/lab-02/Test.csproj new file mode 100644 index 0000000..81f2966 --- /dev/null +++ b/works/lab-02/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