namespace PetsAndFleas; /// /// Represents a dog /// public sealed class Dog : Pet { private static readonly TimeSpan huntingWaitInterval = TimeSpan.FromMinutes(1); private readonly DateTimeProvider _dateTimeProvider; private DateTime? _lastHuntedTime; /// /// Gets the number of animals this dog has hunted /// public int HuntedAnimals { get; private set; } /// /// Initializes a new class /// /// The datetime provider for checking hunting times public Dog(DateTimeProvider dateTimeProvider) { _dateTimeProvider = dateTimeProvider; PrintCtorInfo("Dog"); } /// /// Tries to hunt an animal. /// Dog needs to rest 1 min after a hunt. /// /// True if hunting was successful, false if dog needs to rest. public bool HuntAnimal() { if (_lastHuntedTime.HasValue && _dateTimeProvider.Now - _lastHuntedTime.Value < huntingWaitInterval) { return false; } _lastHuntedTime = _dateTimeProvider.Now; HuntedAnimals++; return true; } /// /// Returns a string representation of the dog /// /// The string that represents the dog public override string ToString() => "I'm a dog"; }