ex-col-02-bucket-chain/BucketChain/Fire.cs

56 lines
No EOL
1.8 KiB
C#

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