Files
basic-computer-games/15_Boxing/csharp/AttackStrategy.cs
Martin Thoma e64fb6795c MAINT: Apply pre-commit
Remove byte-order-marker pre-commit check as there would be
many adjustments necessary
2022-03-05 09:29:23 +01:00

49 lines
1.2 KiB
C#

namespace Boxing;
public abstract class AttackStrategy
{
protected const int KnockoutDamageThreshold = 35;
protected readonly Boxer Other;
protected readonly Stack<Action> Work;
private readonly Action _notifyGameEnded;
public AttackStrategy(Boxer other, Stack<Action> work, Action notifyGameEnded)
{
Other = other;
Work = work;
_notifyGameEnded = notifyGameEnded;
}
public void Attack()
{
var punch = GetPunch();
if (punch.IsBestPunch)
{
Other.DamageTaken += 2;
}
Work.Push(punch.Punch switch
{
Punch.FullSwing => FullSwing,
Punch.Hook => Hook,
Punch.Uppercut => Uppercut,
_ => Jab
});
}
protected abstract AttackPunch GetPunch();
protected abstract void FullSwing();
protected abstract void Hook();
protected abstract void Uppercut();
protected abstract void Jab();
protected void RegisterKnockout(string knockoutMessage)
{
Work.Clear();
_notifyGameEnded();
Console.WriteLine(knockoutMessage);
}
protected record AttackPunch(Punch Punch, bool IsBestPunch);
}