Files
basic-computer-games/15_Boxing/csharp/Boxer.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

46 lines
950 B
C#

namespace Boxing;
public class Boxer
{
private int _wins;
private string Name { get; set; } = string.Empty;
public Punch BestPunch { get; set; }
public Punch Vulnerability { get; set; }
public void SetName(string prompt)
{
Console.WriteLine(prompt);
string? name;
do
{
name = Console.ReadLine();
} while (string.IsNullOrWhiteSpace(name));
Name = name;
}
public int DamageTaken { get; set; }
public void ResetForNewRound() => DamageTaken = 0;
public void RecordWin() => _wins += 1;
public bool IsWinner => _wins >= 2;
public override string ToString() => Name;
}
public class Opponent : Boxer
{
public void SetRandomPunches()
{
do
{
BestPunch = (Punch) GameUtils.Roll(4); // B1
Vulnerability = (Punch) GameUtils.Roll(4); // D1
} while (BestPunch == Vulnerability);
}
}