namespace BucketChain;
///
/// Represents a fire which the bucket chain will attempt to extinguish.
///
public sealed class Fire
{
private readonly double _growRate;
///
/// Creates a new fire with the passed properties.
///
/// Initial size of the fire
/// Rate by which the fire grows with each (chain operation) step
public Fire(double initialFireSize, double growRate)
{
_growRate = growRate;
FireSize = initialFireSize;
}
///
/// Gets the current size of the fire; cannot be smaller than 0.
///
public double FireSize { get; private set; }
///
/// Gets if the fire has been extinguished (= size is 0).
///
public bool Extinguished => FireSize <= 0D;
///
/// The fire is hit by a load of water from a bucket.
/// Reduces the fire size by the amount of liters it received.
///
/// Liters of water
public void GetHitByWater(double amount)
{
FireSize = FireSize - amount < 0D ? 0D : FireSize - amount;
}
///
/// Increases the size of the fire.
/// In this simulation the growth rate is linear & constant and not influenced by the size of the fire.
///
public void BurnHigher()
{
FireSize += _growRate;
}
///
/// Creates a string representation of the fire showing the current size.
/// The size is rounded to whole numbers.
///
/// String representation of the fire
public override string ToString() => $"🔥 {Math.Round(FireSize)}";
}