Demo på Clean Code
This commit is contained in:
30
CleanDemo/Enemy.cs
Normal file
30
CleanDemo/Enemy.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
public class Enemy : IAttackable, IDescribable{
|
||||
public string Name { get; }
|
||||
public bool IsDead { get; private set; }
|
||||
public int Damage { get; }
|
||||
public EnemyType Type { get; }
|
||||
private int _health;
|
||||
|
||||
public Enemy(string name, int health, int damage, EnemyType type) {
|
||||
Name = name;
|
||||
_health = health;
|
||||
Damage = damage;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public void TakeDamage(int amount) {
|
||||
_health -= amount;
|
||||
if (_health <= 0)
|
||||
IsDead = true;
|
||||
}
|
||||
|
||||
public string GetLoot() {
|
||||
return Name == "Dragon" ? "dragon_scale" : "gold";
|
||||
}
|
||||
|
||||
public void Describe() {
|
||||
Console.WriteLine($"--- " + Name + " (enemy) ---");
|
||||
Console.WriteLine($"HP: {_health}");
|
||||
Console.WriteLine($"Type: {Type}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user