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

57 lines
1.2 KiB
C#

namespace PetsAndFleas;
/// <summary>
/// Represents a cat
/// </summary>
public sealed class Cat : Pet
{
private bool _isOnTree;
/// <summary>
/// The number of trees the cat has climbed
/// </summary>
public int TreesClimbed { get; private set; }
public Cat()
{
PrintCtorInfo("cat");
}
/// <summary>
/// Tries to climb a tree
/// </summary>
/// <returns>True if climbing was successful, false if cat is already on a tree</returns>
public bool ClimbOnTree()
{
if (_isOnTree)
{
return false;
}
TreesClimbed++;
_isOnTree = true;
return true;
}
/// <summary>
/// Tries to climb a tree
/// </summary>
/// <returns>True if climbing was successful, false if cat is not on a tree</returns>
public bool ClimbDown()
{
if (!_isOnTree)
{
return false;
}
_isOnTree = false;
return true;
}
/// <summary>
/// Returns a string representation of the cat
/// </summary>
/// <returns>The string that represents the cat</returns>
public override string ToString() => "I'm a cat";
}