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 0000000..ac64f90
Binary files /dev/null and b/works/lab-03/src/lib/MyDll.dll differ