diff --git a/works/lab-06/Code.txt b/works/lab-06/Code.txt new file mode 100644 index 0000000..2cb9ec2 --- /dev/null +++ b/works/lab-06/Code.txt @@ -0,0 +1,89 @@ +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()}"); +} +