Initialized everything and completed Bucket.cs, Fire.cs, Well.cs.

This commit is contained in:
MarcUs7i 2024-12-12 17:04:24 +01:00
parent 176b3b7cbb
commit 6d01e25314
5 changed files with 55 additions and 31 deletions

View file

@ -5,7 +5,8 @@
/// </summary>
public sealed class Bucket
{
// TODO
private readonly double _capacityLiters;
private double _contentLiters;
/// <summary>
/// Creates a new bucket with the given capacity.
@ -13,13 +14,14 @@ public sealed class Bucket
/// <param name="capacityLiters">Bucket capacity in liters</param>
public Bucket(double capacityLiters)
{
// TODO
_capacityLiters = capacityLiters;
_contentLiters = 0D;
}
/// <summary>
/// Gets if this bucket is currently completely empty or not.
/// </summary>
public bool IsEmpty => false; // TODO
public bool IsEmpty => _contentLiters <= 0D;
/// <summary>
/// Fills the bucket to the brim if enough water is available.
@ -30,8 +32,17 @@ public sealed class Bucket
/// <returns>The amount taken for filling the bucket</returns>
public double Fill(double maxAvailable)
{
// TODO
return -1D;
if (_capacityLiters - _contentLiters <= 0D)
{
return 0D;
}
maxAvailable = Math.Abs(_capacityLiters - maxAvailable);
_contentLiters = _contentLiters + maxAvailable > _capacityLiters
? _capacityLiters
: _contentLiters + maxAvailable;
return maxAvailable;
}
/// <summary>
@ -40,7 +51,8 @@ public sealed class Bucket
/// <returns>Amount emptied from the bucket, in liters</returns>
public double Empty()
{
// TODO
return -1D;
var content = _contentLiters;
_contentLiters = 0D;
return content;
}
}