Demo på Clean Code

This commit is contained in:
2026-03-08 11:55:18 +01:00
parent fe9a1e6400
commit f966c97d32
10 changed files with 227 additions and 0 deletions

30
CleanDemo/Enemy.cs Normal file
View 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}");
}
}