Files
2026-11-25 13:02:06 +00:00

91 lines
2.6 KiB
Plaintext

var pikachu = new Pikachu("qwe", 12, 3);
Console.WriteLine(pikachu.ToString());
abstract class Pokemon
{
public Pokemon() : this(DEFAULT_NAME, DEFAULT_HP, DEFAULT_LVL) {}
public Pokemon(string name) : this(name, hp: DEFAULT_HP, DEFAULT_LVL) {}
public Pokemon(string name, short hp) : this(name, hp, DEFAULT_LVL) {}
public Pokemon(string name, short hp, byte level)
{
Name = name;
Hp = hp;
Level = level;
//Count++
}
protected string name;
protected short hp;
protected byte level;
protected const string DEFAULT_NAME = "UNKNOWN";
protected const short
DEFAULT_HP = 100,
MAX_HP = 999,
MIN_HP = 0;
protected const byte
DEFAULT_LVL = 1,
MAX_LVL = 100,
MIN_LVL = 1;
public string Name
{
get => name;
set => name = !(string.IsNullOrEmpty(value))
? value
: throw new Exception("Name cannot be empty or Null");
}
public short Hp
{
get => hp;
set => hp = value > MAX_HP || value < MIN_HP
? value
: throw new Exception($"Hp cannot be less than {MIN_HP} and greater than {MAX_HP}");
}
public byte Level
{
get => level;
set => level = value > MAX_LVL || value < MIN_LVL
? value
: throw new Exception($"Hp cannot be less than {MIN_LVL} and greater than {MAX_LVL}");
}
public abstract override string ToString();
public abstract void ShowInfo();
}
interface IAttack
{
public void Attack();
}
class Pikachu : Pokemon, IAttack
{
public Pikachu(string name, short hp, byte level) : base() {}
public override string ToString() => $"Pikachu({Name}, {Hp},{Level})";
public override void ShowInfo() => Console.WriteLine($"|INFO|==============\nName: {Name}\nHp: {Hp}\nLevel: {Level}");
public void Attack() => Console.WriteLine("Electro");
}
class Squirtle : Pokemon, IAttack
{
public Squirtle() : base() {}
public override string ToString() => $"Squirtle({Name}, {Hp},{Level})";
public override void ShowInfo() => Console.WriteLine($"|INFO|==============\nName: {Name}\nHp: {Hp}\nLevel: {Level}");
public void Attack() => Console.WriteLine("Aqua");
}
class Charmander : Pokemon, IAttack
{
public Charmander() : base() {}
public override string ToString() => $"Charmander({Name}, {Hp},{Level})";
public override void ShowInfo() => Console.WriteLine($"|INFO|==============\nName: {Name}\nHp: {Hp}\nLevel: {Level}");
public void Attack() => Console.WriteLine("Chair");
}