mirror of
https://github.com/onyx-and-iris/Lottery.git
synced 2026-07-24 21:54:23 +00:00
87 lines
3.3 KiB
C#
87 lines
3.3 KiB
C#
namespace Lottery
|
|
{
|
|
internal record Sample(int Lower, int Upper, int Count);
|
|
|
|
/// <summary>
|
|
/// Abstract base class for lotteries.
|
|
/// Sample property must be overridden.
|
|
/// </summary>
|
|
internal abstract class Lottery
|
|
{
|
|
protected virtual Sample Sample => throw new NotImplementedException();
|
|
public virtual string Play() => $"Numbers: {string.Join(", ", Generator.Generate(Sample))}";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Concrete Lotto Lottery class.
|
|
/// Generates six balls from 1 to 59.
|
|
/// </summary>
|
|
internal class LottoLottery : Lottery
|
|
{
|
|
protected override Sample Sample { get; } = new(Lower: 1, Upper: 59, Count: 6);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Abstract base class for Lotteries with Special values.
|
|
/// It subclasses Lottery.
|
|
/// SpecialSample and SpecialIdentifier properties must be overridden.
|
|
/// </summary>
|
|
internal abstract class LotteryWithSpecial : Lottery
|
|
{
|
|
protected virtual Sample SpecialSample => throw new NotImplementedException();
|
|
protected virtual string SpecialIdentifier => throw new NotImplementedException();
|
|
|
|
public override string Play()
|
|
{
|
|
return string.Join("\n", [
|
|
$"Numbers: {string.Join(", ", Generator.Generate(Sample))}",
|
|
$"{SpecialIdentifier}: {string.Join(", ", Generator.Generate(SpecialSample))}",
|
|
]);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Concrete class for EuroMillions lottery.
|
|
/// Generates five balls from 1 to 50 and two lucky stars from 1 to 12.
|
|
/// </summary>
|
|
internal class EuroMillionsLottery : LotteryWithSpecial
|
|
{
|
|
protected override Sample Sample { get; } = new(Lower: 1, Upper: 50, Count: 5);
|
|
protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 12, Count: 2);
|
|
protected override string SpecialIdentifier => "Lucky Stars";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Concrete class for SetForLifeLottery lottery.
|
|
/// Generates five balls from 1 to 47 and one life ball from 1 to 10.
|
|
/// </summary>
|
|
internal class SetForLifeLottery : LotteryWithSpecial
|
|
{
|
|
protected override Sample Sample { get; } = new(Lower: 1, Upper: 47, Count: 5);
|
|
protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 10, Count: 1);
|
|
protected override string SpecialIdentifier => "Life Ball";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Concrete class for ThunderballLottery lottery.
|
|
/// Generates fives balls from 1 to 39 and one thunderball from 1 to 14.
|
|
/// </summary>
|
|
internal class ThunderballLottery : LotteryWithSpecial
|
|
{
|
|
protected override Sample Sample { get; } = new(Lower: 1, Upper: 39, Count: 5);
|
|
protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 14, Count: 1);
|
|
protected override string SpecialIdentifier => "Thunderball";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Concrete class for PowerballLottery lottery.
|
|
/// Generates five balls from 1 to 69 and one powerball from 1 to 26.
|
|
/// </summary>
|
|
internal class PowerballLottery : LotteryWithSpecial
|
|
{
|
|
protected override Sample Sample { get; } = new(Lower: 1, Upper: 69, Count: 5);
|
|
protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 26, Count: 1);
|
|
protected override string SpecialIdentifier => "Powerball";
|
|
}
|
|
}
|