Implementation

This commit is contained in:
2024-01-17 04:11:30 +01:00
parent cb432f2b4a
commit 422379cceb
16 changed files with 244 additions and 5 deletions

View File

@ -0,0 +1,9 @@
namespace CShocker.Ranges;
public class DurationRange : RandomIntegerRange
{
public DurationRange(Range range) : base(range, new Range(0, 30000))
{
}
}

View File

@ -0,0 +1,9 @@
namespace CShocker.Ranges;
public class IntensityRange : RandomIntegerRange
{
public IntensityRange(Range range) : base(range, new Range(0, 100))
{
}
}

View File

@ -0,0 +1,21 @@
namespace CShocker.Ranges;
public abstract class RandomIntegerRange
{
private readonly Range _range;
internal RandomIntegerRange(Range range, Range limits)
{
if (range.Max - range.Min < 0)
throw new ArgumentException("Min has to be less or equal Max");
if (range.Min < limits.Min || range.Min > limits.Max)
throw new ArgumentOutOfRangeException(nameof(limits.Min), "Min has to be withing Range 0-100");
if (range.Max < limits.Min || range.Max > limits.Max)
throw new ArgumentOutOfRangeException(nameof(range.Max), "Max has to be withing Range 0-100");
this._range = range;
}
internal int GetRandomRangeValue()
{
return Random.Shared.Next(_range.Min, _range.Max);
}
}

12
CShocker/Ranges/Range.cs Normal file
View File

@ -0,0 +1,12 @@
namespace CShocker.Ranges;
public struct Range
{
public short Min, Max;
public Range(short min, short max)
{
Min = min;
Max = max;
}
}