mirror of
				https://github.com/onyx-and-iris/Lottery.git
				synced 2025-11-03 23:11:45 +00:00 
			
		
		
		
	add document strings
Limits are now initialized and private to each Lottery class
This commit is contained in:
		
							parent
							
								
									ff4d77283c
								
							
						
					
					
						commit
						3da6f66deb
					
				@ -2,6 +2,11 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    internal class Generator
 | 
					    internal class Generator
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Simple algorithm for generating a list of unique numbers of Limits.Count size
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="Limits">Defines the amount of numbers to generate, the max and min values</param>
 | 
				
			||||||
 | 
					        /// <returns>The list of numbers is returned sorted in ascending order.</returns>
 | 
				
			||||||
        public static List<int> Generate(Limits Limits)
 | 
					        public static List<int> Generate(Limits Limits)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            List<int> Candidates = Enumerable.Range(Limits.Lower, Limits.Upper).ToList();
 | 
					            List<int> Candidates = Enumerable.Range(Limits.Lower, Limits.Upper).ToList();
 | 
				
			||||||
 | 
				
			|||||||
@ -1,14 +1,33 @@
 | 
				
			|||||||
namespace Lottery
 | 
					namespace Lottery
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    internal class Lottery(Limits limits)
 | 
					    internal record Limits(int Count, int Lower, int Upper);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// Abstract base class for lotteries.
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    internal class Lottery
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        protected Limits Limits => limits;
 | 
					        protected virtual Limits Limits => throw new NotImplementedException();
 | 
				
			||||||
        public virtual string Play() => $"Numbers: {string.Join(", ", Generator.Generate(Limits))}";
 | 
					        public virtual string Play() => $"Numbers: {string.Join(", ", Generator.Generate(Limits))}";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    internal class LotteryWithSpecial(Limits limits, Limits specialLimits) : Lottery(limits)
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// Concrete UKLotto Lottery class.
 | 
				
			||||||
 | 
					    /// Generates six balls from 1 to 59.
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    internal class UKLottoLottery : Lottery
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        protected Limits SpecialLimits => specialLimits;
 | 
					        protected override Limits Limits { get; } = new(Count: 6, Lower: 1, Upper: 59);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// Abstract base class for Lotteries with Special values.
 | 
				
			||||||
 | 
					    /// It subclasses Lottery.
 | 
				
			||||||
 | 
					    /// SpecialLimits and SpecialIdentifier properties must be overridden.
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    internal class LotteryWithSpecial : Lottery
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        protected virtual Limits SpecialLimits => throw new NotImplementedException();
 | 
				
			||||||
        protected virtual string SpecialIdentifier => throw new NotImplementedException();
 | 
					        protected virtual string SpecialIdentifier => throw new NotImplementedException();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public override string Play()
 | 
					        public override string Play()
 | 
				
			||||||
@ -20,18 +39,36 @@
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    internal class EuroMillionsLottery(Limits limits, Limits specialLimits) : LotteryWithSpecial(limits, specialLimits)
 | 
					    /// <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 Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 50);
 | 
				
			||||||
 | 
					        protected override Limits SpecialLimits { get; } = new(Count: 2, Lower: 1, Upper: 12);
 | 
				
			||||||
        protected override string SpecialIdentifier => "Lucky Stars";
 | 
					        protected override string SpecialIdentifier => "Lucky Stars";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    internal class SetForLifeLottery(Limits limits, Limits specialLimits) : LotteryWithSpecial(limits, specialLimits)
 | 
					    /// <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 Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 47);
 | 
				
			||||||
 | 
					        protected override Limits SpecialLimits { get; } = new(Count: 1, Lower: 1, Upper: 10);
 | 
				
			||||||
        protected override string SpecialIdentifier => "Life Ball";
 | 
					        protected override string SpecialIdentifier => "Life Ball";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    internal class ThunderballLottery(Limits limits, Limits specialLimits) : LotteryWithSpecial(limits, specialLimits)
 | 
					    /// <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 Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 39);
 | 
				
			||||||
 | 
					        protected override Limits SpecialLimits { get; } = new(Count: 1, Lower: 1, Upper: 14);
 | 
				
			||||||
        protected override string SpecialIdentifier => "Thunderball";
 | 
					        protected override string SpecialIdentifier => "Thunderball";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,14 +1,12 @@
 | 
				
			|||||||
namespace Lottery
 | 
					namespace Lottery
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    internal record Limits(int Count, int Lower, int Upper);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public partial class MainPage : ContentPage
 | 
					    public partial class MainPage : ContentPage
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        readonly List<Lottery> Lotteries = [
 | 
					        readonly List<Lottery> Lotteries = [
 | 
				
			||||||
            new Lottery(limits: new Limits(6, 1, 59)), 
 | 
					            new UKLottoLottery(), 
 | 
				
			||||||
            new EuroMillionsLottery(limits: new Limits(5, 1, 50), specialLimits: new Limits(2, 1, 12)), 
 | 
					            new EuroMillionsLottery(), 
 | 
				
			||||||
            new SetForLifeLottery(limits: new Limits(5, 1, 47), specialLimits: new Limits(1, 1, 10)), 
 | 
					            new SetForLifeLottery(), 
 | 
				
			||||||
            new ThunderballLottery(limits: new Limits(5, 1, 39), specialLimits: new Limits(1, 1, 14))
 | 
					            new ThunderballLottery()
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
        const KindOfLottery DefaultLottery = KindOfLottery.Uk;
 | 
					        const KindOfLottery DefaultLottery = KindOfLottery.Uk;
 | 
				
			||||||
        Lottery Lottery;
 | 
					        Lottery Lottery;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user