diff --git a/works/lab-07/Code.txt b/works/lab-07/Code.txt new file mode 100644 index 0000000..12d728b --- /dev/null +++ b/works/lab-07/Code.txt @@ -0,0 +1,73 @@ +using System.Globalization; + +class Pokemon +{ + // CONSTANTS + private const byte + MIN_LEVEL = 1, + MAX_LEVEL = 100; + private const short + MIN_HP = 0, + MAX_HP = 2500; + private const string DEFAULT_NAME = "Unknown"; + + + // FIELDS + protected string name = DEFAULT_NAME; + protected byte level = MIN_LEVEL; + protected short hp = MIN_HP; + + + // PROPS + public string Name + { + get => name; + set => name = value ?? DEFAULT_NAME; + } + public byte Level + { + get => level; + set + { + if (value > MAX_LEVEL) level = MAX_LEVEL; + else if(value < MIN_LEVEL) level = MIN_LEVEL; + else level = value; + } + } + public short Hp + { + get => hp; + set + { + if (value > MAX_HP) hp = MAX_HP; + else if(value < MIN_HP) hp = MIN_HP; + else hp = value; + } + } + + + // CONSTRUCTORS + public Pokemon(string name) + { + Name = name; + } + public Pokemon(string name, byte level) : this(name) + { + Level = level; + } + public Pokemon(string name, byte level, short hp) : this(name, level) + { + Hp = hp; + } + + + // METHODS + public override string ToString() => $"Pokemon: {Name}\tLevel: {Level}\tHp: {Hp}"; + public virtual void Attack() => Console.WriteLine($"{Name} is attacking!"); + public void ShowInfo() => Console.WriteLine($"=== INFORMATION ===\nPokemon: {Name}\t(level: {Level} | hp: {Hp})"); +} + +class OtherPokemon : Pokemon +{ + +} \ No newline at end of file