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

57 lines
1.3 KiB
C#

namespace PetsAndFleas;
/// <summary>
/// Abstract class for pets
/// </summary>
public abstract class Pet
{
/// <summary>
/// Next available pet ID
/// </summary>
public static int NextPetId { get; private set; }
/// <summary>
/// The unique pet ID
/// </summary>
public int PetId { get; }
/// <summary>
/// The remaining bites for this pet
/// </summary>
public int RemainingBites { get; private set; } = 100;
/// <summary>
/// Initializes a new <see cref="Pet"/> class
/// </summary>
protected Pet()
{
NextPetId++;
PetId = NextPetId;
}
/// <summary>
/// Reduces the remaining bites for this pet
/// </summary>
/// <param name="bites">Number of bites to take</param>
/// <returns>The actual number of bites taken</returns>
public int GetBitten(int bites)
{
if (bites <= 0)
{
return 0;
}
int actualBites = Math.Min(bites, RemainingBites);
RemainingBites -= actualBites;
return actualBites;
}
/// <summary>
/// Prints information about the constructor
/// </summary>
/// <param name="petType">The type of pet being created</param>
protected static void PrintCtorInfo(string petType)
{
Console.WriteLine($"Creating a new {petType}");
}
}