diff --git a/works/lab-06/Code.txt b/works/lab-06/Code.txt deleted file mode 100644 index 2cb9ec2..0000000 --- a/works/lab-06/Code.txt +++ /dev/null @@ -1,89 +0,0 @@ -using System.Globalization; - -var pokemon = new Pokemon(); - -pokemon.ShowInfo(); -// Console.WriteLine($@"{pokemon.PokemonLevel} -// {pokemon.PokemonHp} -// {pokemon.PokemonName}"); - -class Pokemon -{ - // FIELDS - private string pokemonName; - private byte pokemonLevel; - private short pokemonHp; - - private const byte - MAX_NAME_LENGTH = 25, - MIN_LEVEL = 1, - MAX_LEVEL = 100; - private const short - MIN_HP = 0, - MAX_HP = 2500; - private const string DEFAULT_NAME = "Unknown"; - - // PROPS - public string PokemonName - { - get => pokemonName; - set - { - if(value != String.Empty) - { - if(value.Length > MAX_NAME_LENGTH) - { - pokemonName = value; // Cut method - return; - } - - pokemonName = value; - } - } - } - - public byte PokemonLevel - { - get => pokemonLevel; - set - { - if (value < MIN_LEVEL) pokemonLevel = 1; - else if (value > MAX_LEVEL) pokemonLevel = 100; - else pokemonLevel = value; - } - } - - public short PokemonHp - { - get => pokemonHp; - set - { - if (value < MIN_HP) pokemonHp = 0; - else if (value > MAX_HP) pokemonHp = 2500; - else pokemonHp = value; - } - } - - - // CONSTRUCTORS - public Pokemon(string pokemonName = DEFAULT_NAME) - { - this.pokemonName = pokemonName; - } - - public Pokemon(string pokemonName, short pokemonHp = 100) : this(pokemonName) - { - this.pokemonHp = pokemonHp; - } - - public Pokemon(string pokemonName, short pokemonHp = 100, byte pokemonLevel = MIN_LEVEL) : this(pokemonName, pokemonHp) - { - this.pokemonLevel = pokemonLevel; - } - - - // METHODS - public override string ToString() => $"Name: {pokemonName} Level: {pokemonLevel} HP: {pokemonHp}"; - public void ShowInfo() => Console.WriteLine($"=== Information ===\n{ToString()}"); -} - diff --git a/works/lab-06/Readme.md b/works/lab-06/Readme.md new file mode 100644 index 0000000..cb30ca0 --- /dev/null +++ b/works/lab-06/Readme.md @@ -0,0 +1,5 @@ +# Лабораторная работа №7 + +* **Студент:** *Квасницкий Александр Александрович* +* **lab:** *07* +--- \ No newline at end of file diff --git a/works/lab-06/src/Program.cs b/works/lab-06/src/Program.cs new file mode 100644 index 0000000..31ea913 --- /dev/null +++ b/works/lab-06/src/Program.cs @@ -0,0 +1,193 @@ +using HelpMethods; +using System; + +namespace Test +{ + internal class Program + { + static Random rand = new Random(); + static void Main(string[] args) + { + var pokemon1 = new Pokemon("Pokemon1", 100, 33); + var pokemon2 = new Pokemon("Pokemon2", 100); + + pokemon1.ShowInfo(); + StringHelp.Br(); + + pokemon2.ShowInfo(); + StringHelp.Br(); + + + Console.WriteLine("============================================"); + + pokemon1.TakeDamage(34); + pokemon2.Heal(19); + + pokemon1.ShowInfo(); + StringHelp.Br(); + + pokemon2.ShowInfo(); + StringHelp.Br(); + + + Console.WriteLine($"============================================\nCount of pokemons: {Pokemon.Count}"); + pokemon1.IsStronger(pokemon2); + + + Console.WriteLine("\n============================================"); + pokemon1.Battle(pokemon2); + } + } + + class Pokemon + { + // FIELDS + private string pokemonName; + private byte pokemonLevel; + private short pokemonHp; + private short pokemonAttack; + + public static byte count; + + + // CONST + private const byte + MAX_NAME_LENGTH = 25, + MIN_LEVEL = 1, + MAX_LEVEL = 100; + private const short + MIN_HP = 0, + MAX_HP = 2500, + MIN_ATTACK = 5, + MAX_ATTACK = 250; + private const string DEFAULT_NAME = "Unknown"; + + + // PROPS + public string PokemonName + { + get => pokemonName; + set => pokemonName = StringHelp.CutString(value, MAX_NAME_LENGTH, DEFAULT_NAME); + } + public byte PokemonLevel + { + get => pokemonLevel; + set + { + if (value < MIN_LEVEL) pokemonLevel = MIN_LEVEL; + else if (value > MAX_LEVEL) pokemonLevel = MAX_LEVEL; + else pokemonLevel = value; + } + } + public short PokemonHp + { + get => pokemonHp; + set + { + if (value < MIN_HP) pokemonHp = MIN_HP; + else if (value > MAX_HP) pokemonHp = MAX_HP; + else pokemonHp = value; + } + } + public short PokemonAttack + { + get => pokemonAttack; + set + { + if (value < MIN_ATTACK) pokemonAttack = MIN_ATTACK; + else if (value > MAX_ATTACK) pokemonAttack = MAX_ATTACK; + else pokemonAttack = value; + } + } + + public static byte Count { get; } + + + // CONSTRUCTORS + public Pokemon() : this(DEFAULT_NAME, MIN_HP, MIN_ATTACK, MIN_LEVEL) { } + public Pokemon(string pokemonName) : this(pokemonName, MIN_HP, MIN_ATTACK, MIN_LEVEL) { } + public Pokemon(string pokemonName, short pokemonHp) : this(pokemonName, pokemonHp, MIN_ATTACK, MIN_LEVEL) { } + public Pokemon(string pokemonName, short pokemonHp, short pokemonAttack) : this(pokemonName, pokemonHp, pokemonAttack, MIN_LEVEL) { } + public Pokemon(string pokemonName, short pokemonHp, short pokemonAttack, byte pokemonLevel) + { + PokemonName = pokemonName; + PokemonLevel = pokemonLevel; + PokemonHp = pokemonHp; + PokemonAttack = pokemonAttack; + count++; + } + + + // METHODS + public override string ToString() => $"Name: {PokemonName} HP: {PokemonHp} Attack: {PokemonAttack} Level: {PokemonLevel}"; + public void ShowInfo() => Console.WriteLine($"=== Information ===\nName: {PokemonName}\t(HP: {PokemonHp} | Attack: {PokemonAttack} | Level {PokemonLevel})"); + public void TakeDamage(short damage) => PokemonHp -= Math.Abs(damage); + public void Heal(short value) => PokemonHp += Math.Abs(value); + public void IsStronger(Pokemon enemy) + { + byte scorePlayer1 = 0, scorePlayer2 = 0; + + if (PokemonHp > enemy.PokemonHp) scorePlayer1++; + else if (PokemonHp < enemy.PokemonHp) scorePlayer2++; + else { scorePlayer1++; scorePlayer2++; } + + if (PokemonLevel > enemy.PokemonLevel) scorePlayer1++; + else if (PokemonLevel < enemy.PokemonLevel) scorePlayer2++; + else { scorePlayer1++; scorePlayer2++; } + + if (scorePlayer1 > scorePlayer2) Console.WriteLine($"{PokemonName} stronger!"); + else if (scorePlayer1 < scorePlayer2) Console.WriteLine($"{enemy.PokemonName} stronger!"); + else Console.WriteLine("Draw!"); + } + public void Battle(Pokemon enemy) + { + short round = 1; + + Console.WriteLine("The battle has begun!\n"); + + while(true) + { + if (PokemonHp < 1) + { + Console.WriteLine($"The {PokemonName} is unconscious!\n{enemy.PokemonName} won!"); + break; + } + + if (enemy.PokemonHp < 1) + { + Console.WriteLine($"The {enemy.PokemonName} is unconscious!\n{PokemonName} won!"); + break; + } + + + Console.WriteLine($"Round №{round}"); + if(round % 2 == 0) + { + if(enemy.PokemonHp - PokemonAttack < 1) + { + Console.WriteLine($"{PokemonName} attacked {enemy.PokemonName}\t({enemy.PokemonHp} - {PokemonAttack} = 0)\n"); + enemy.PokemonHp = 0; + continue; + } + + Console.WriteLine($"{PokemonName} attacked {enemy.PokemonName}\t({enemy.PokemonHp} - {PokemonAttack} = {enemy.PokemonHp - PokemonAttack})\n"); + enemy.PokemonHp -= PokemonAttack; + } + else + { + if (PokemonHp - enemy.PokemonAttack < 1) + { + Console.WriteLine($"{enemy.PokemonName} attacked {PokemonName}\t({PokemonHp} - {enemy.PokemonAttack} = 0)\n"); + PokemonHp = 0; + continue; + } + + Console.WriteLine($"{enemy.PokemonName} attacked {PokemonName}\t({PokemonHp} - {enemy.PokemonAttack} = {PokemonHp - enemy.PokemonAttack})\n"); + PokemonHp -= enemy.PokemonAttack; + } + + round++; + } + } + } +} \ No newline at end of file diff --git a/works/lab-06/src/Test.csproj b/works/lab-06/src/Test.csproj new file mode 100644 index 0000000..81f2966 --- /dev/null +++ b/works/lab-06/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-06/src/lib/MyDll.dll b/works/lab-06/src/lib/MyDll.dll new file mode 100644 index 0000000..cfb32d5 Binary files /dev/null and b/works/lab-06/src/lib/MyDll.dll differ