public void Attack(Dummy target)
{ if (this.durabilityPoints <= 0)
{ throw new InvalidOperationException("Axe is broken.");
} target.TakeAttack(this.attackPoints); this.durabilityPoints -= 1;
}
}
Dummy.cs public class Dummy
{
private int health; private int experience; public Dummy(int health, int experience)
{ this.health = health; this.experience = experience;
}
public int Health { get { return this.health; }
} public void TakeAttack(int attackPoints)
{ if (this.IsDead())
{ throw new InvalidOperationException("Dummy is dead.");
} this.health -= attackPoints;
} public int GiveExperience()
{ if (!this.IsDead())
{ throw new InvalidOperationException("Target is not dead.");
} return this.experience;
} public bool IsDead()
{ return this.health <= 0;