Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Kid         kid = new Kid();
            int         height;
            Gender      gender;
            WeekDay     weekDay;
            Attractions attraction;

            Console.WriteLine("Enter kid height in cm: ");
            while (!int.TryParse(Console.ReadLine(), out height))
            {
                Console.WriteLine("Height is not a number");
            }

            kid.Height = height;

            Console.WriteLine("Choose Week Day (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday): ");
            while (!Enum.TryParse(Console.ReadLine(), out weekDay))
            {
                Console.WriteLine("Enter Week Day in right format: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday");
            }

            Console.WriteLine("Choose kid gender (Boy, Girl): ");
            while (!Enum.TryParse(Console.ReadLine(), out gender))
            {
                Console.WriteLine("Uknown gender. Please choose one of: Boy, Girl");
            }

            kid.Gender = gender;

            Console.WriteLine("Enter Kid Name: ");
            kid.Name = Console.ReadLine();

            Console.WriteLine("Which Attraction kid want to visit (Batman, Swan, Pony): ");
            while (!Enum.TryParse(Console.ReadLine(), out attraction))
            {
                Console.WriteLine($"Uknown Attraction name. Please choose one of: Batman, Swan, Pony.");
            }

            KidAllowedToAttractions(weekDay, kid, attraction);

            Console.ReadKey();
        }
Exemplo n.º 2
0
 static bool IsKidAllowed(Attractions attraction, Kid kid)
 {
     if (attraction == Attractions.Batman & kid.Height > 150 & kid.Gender == Gender.Boy)
     {
         return(true);
     }
     if (attraction == Attractions.Swan & kid.Gender == Gender.Girl & (kid.Height > 120 & kid.Height < 140))
     {
         return(true);
     }
     if (attraction == Attractions.Swan & kid.Gender == Gender.Boy & kid.Height < 140)
     {
         return(true);
     }
     if (attraction == Attractions.Pony)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
 static bool IsKidAllowed(Attractions attraction, Kid kid)
 {
     if (attraction == Attractions.Batman & kid.Height > AttractionSettings.GetMinimumHeightForBatman() & kid.Gender == Gender.Male)
     {
         return(true);
     }
     if (attraction == Attractions.Swan & kid.Gender == Gender.Female & (kid.Height > AttractionSettings.GetMinimumHeightForSwan() & kid.Height < AttractionSettings.GetMaximumHeightForSwan()))
     {
         return(true);
     }
     if (attraction == Attractions.Swan & kid.Gender == Gender.Male & kid.Height < AttractionSettings.GetMaximumHeightForSwan())
     {
         return(true);
     }
     if (attraction == Attractions.Pony)
     {
         return(true);
     }
     return(false);
 }
        //Get random valid attraction for Kid based on Attraction conditions
        // return null or 1 Attraction
        private Attraction GetRandomValidAttractionForKid(Kid kid)
        {
            // using for store ALL available attraction ( based on rules/ condition ) related to current Kid.
            var rand = new Random();

            kid.SetKidAction("Trying to get list of avaiable Attractions");

            // Try to find available attractions
            var listOfAvailableAttractionForKid =
                ListOfOpenRandomAttractions.GetListOfGeneratedAttractions()
                .Where(attraction => attraction.DoValidation(kid, WeekDay))
                .ToList();

            // return null Or Random attraction.
            // null - if there no available attraction for Kid.
            // Random attraction calculated as Random LIST index for all available attractions for 1 kid.
            //    List index started from 0, thats why total count of available attractions should be decreased on 1 for count > 1.
            return(listOfAvailableAttractionForKid.Count <= 0?
                   null:
                   listOfAvailableAttractionForKid[rand.Next(0, listOfAvailableAttractionForKid.Count > 1 ?
                                                             listOfAvailableAttractionForKid.Count :
                                                             listOfAvailableAttractionForKid.Count - 1)]);
        }
        // Method RidingOnAttractions use for riding emulation.
        // Method will call from ToRide() in separete thread based on logic from ThreadPool.QueueUserWorkItem
        private static void RidingOnAttractions(Kid kids, Attraction currentAttraction)
        {
            var rand = new Random();

            // Set Action for kid with attraction name and durations
            kids.SetKidAction("I'm staring to ride on => " + currentAttraction.Name + " for " + currentAttraction.Duration + " sec");
            kids.SetBusyStatus(true);

            // Adding money to Global cash box
            currentAttraction.AddMoneyToCashBox();

            //Increase Kid satisfaction degree
            kids.ChangeSatisfactionDegree(rand.Next(10, 20));

            //Attraction payment
            kids.ChangeMoneyAmount(currentAttraction.Price);

            // Riding emulation by sleepinn on attraction duration x1000 (as Seconds)
            Thread.Sleep(currentAttraction.Duration * 1000);

            // Then attraction finished - update status to Finished + free
            kids.SetKidAction("I've FINISHED to ride on => " + currentAttraction.Name);
            kids.SetBusyStatus(false);
        }
Exemplo n.º 6
0
 static void ShowKidAfterAttractionClosing(Kid kid)
 {
     Console.WriteLine($"{kid.Name}  {kid.LevelOfHappines} {kid.Money}");
 }