ex-inh-02-pets/PetsAndFleas/Flea.cs
2025-03-05 18:55:45 +01:00

44 lines
1.1 KiB
C#

namespace PetsAndFleas;
/// <summary>
/// Represents a flea
/// </summary>
public sealed class Flea
{
/// <summary>
/// The current selected <see cref="Pet"/>
/// </summary>
public Pet? CurrentPet { get; private set; }
/// <summary>
/// The total bites taken
/// </summary>
public int TotalBites { get; private set; }
/// <summary>
/// Sets the current <see cref="Pet"/>
/// </summary>
/// <param name="pet">The pet to select</param>
public void JumpOnPet(Pet? pet)
{
CurrentPet = pet;
}
/// <summary>
/// Bites the current <see cref="Pet"/>
/// </summary>
/// <param name="bites">How many bites to take</param>
/// <returns>The number of bites taken</returns>
public int BitePet(int bites)
{
var bitesTaken = CurrentPet?.GetBitten(bites) ?? 0;
TotalBites += bitesTaken;
return bitesTaken;
}
/// <summary>
/// Returns a string representation of the flea
/// </summary>
/// <returns>The string that represents the flea</returns>
public override string ToString() => "I'm a flea";
}