Exemple #1
0
        /// <summary>
        /// Generates Events and Tickets Data, then return the list of events that have been generated
        /// </summary>
        /// <param name="eventsGenerated">Output the list of events had been generated</param>
        /// <param name="eventsToGenerate">A user specified number of evnets being generated. Assign a negative number for a random quantity.</param>
        /// <param name="clearAllData">True: Wipe all the exsiting events and tickets data</param>

        public static void GenerateData(out List <Event> eventsGenerated, int eventsToGenerate = -1, bool clearAllData = false)
        {
            if (clearAllData)
            {
                //Clear all events and tickets data in the corresponding lists in World
                World.Events.Clear();
                World.Tickets.Clear();
                //Reset the next event id variable
                World.NextEventId = 0;
            }

            //Quantity of events being generated
            int eventsQuantity;

            //Check if the 'eventsToGenerate' (user set) has a genuine value (greater than 0)
            if (eventsToGenerate > 0)
            {
                //Apply the number and limit it to the remaining capcity of the world
                eventsQuantity = (int)Math.Min(eventsToGenerate, World.RemainingEventCapacity);
            }
            else //User has not specified a number, randomize the quantity to generate
            {
                //Set the quantity range of events generation
                Range generateRange = EventAmountRangeAdjusted;
                //Randomize the quantity of events being generated (int) from the range
                eventsQuantity = (int)Mathc.RandomRange(generateRange);
            }

            //Generate the events with the random value and output it
            eventsGenerated = GenerateEvents(eventsQuantity);
            //Add the events that have been generated
            World.AddEvents(eventsGenerated);
        }
Exemple #2
0
        /// <summary>
        ///Generate and return Random coordinates
        /// </summary>
        /// <param name="GeneratedEvents"></param>
        /// <returns>A random and valid coordinates</returns>
        public static Vector2 Randomcoordinates(List <Event> GeneratedEvents = null)
        {
            Vector2 coordinates;

            //Repeat generating coordinates until it is valid
            do
            {
                double x;
                double y;
                switch (World.CoordinateSystem)
                {
                default:
                case World.coordinateSystem.Integer:
                    //Randomize the x and y value within the world axis range
                    //Adding 1 to the max value are exclusive when convert to int (Unless the random is exactly 1 which is impossible)
                    x = Mathc.RandomRange(World.AxisX.min, World.AxisY.max + 1);
                    y = Mathc.RandomRange(World.AxisY.min, World.AxisY.max + 1);
                    //Create a new coordinates(Vector2)
                    coordinates = new Vector2(Math.Floor(x), Math.Floor(y));
                    break;

                //Randomize the x and y value within the world axis range
                case World.coordinateSystem.Decimal:
                    x = Mathc.RandomRange(World.AxisX);
                    y = Mathc.RandomRange(World.AxisY);
                    //Convert the coordinates into decimal places and create a new coordinates (Vector2)
                    coordinates = new Vector2(Mathc.ConvertToDecimalPlace(x, World.DecimalPlacesForDecimalCoordinateSystem), Mathc.ConvertToDecimalPlace(y, World.DecimalPlacesForDecimalCoordinateSystem));
                    break;
                }
            } while (!validCoordinates(coordinates, GeneratedEvents)); //Check if the coordinates are valid, repeat if invalid

            return(coordinates);
        }
Exemple #3
0
        /// <summary>
        /// Generates and returns a single event in a specific location
        /// </summary>
        /// <param name="location">The specific location the event being generated</param>
        /// <returns>A single Event object</returns>
        public static Event GenerateEvent(Vector2 location)
        {
            Event evt          = new Event(location);                        // Create a new event object
            int   totalTickets = (int)Mathc.RandomRange(ticketAmountRange);  //Randomize the quantity of total ticket

            evt.AddTickets(GenerateTickets(totalTickets, TicketPriceRange)); //Generate a list of Ticket objects and pass it to the Event object
            return(evt);
        }
Exemple #4
0
        /// <summary>
        /// Generates and return a list of Ticket objects with random quantities and price
        /// </summary>
        /// <param name="totalTickets">The total quanity of tickets (NOT a Ticket object)</param>
        /// <param name="priceRange">The price range of tickets</param>
        /// <returns>A list of tickets</returns>
        static List <Ticket> GenerateTickets(int totalTickets, Range priceRange)
        {
            //Create a new list to store Ticket objects for the event
            List <Ticket> _tickets = new List <Ticket>();

            //Generate Ticket objects until the totalTickets is 0
            while (totalTickets > 0)
            {
                //Represent the quantity of tickets being generated
                int ticketQuantity = (int)Mathc.RandomRange(1, totalTickets);
                //Randomize the price with the range
                double ticketPrice = Mathc.RandomRange(priceRange);
                //Generate a new Ticket Object
                _tickets.Add(new Ticket(ticketPrice, ticketQuantity));
                //Reduce the totalTickets value
                totalTickets -= ticketQuantity;
            }
            return(_tickets); //Return the whole list
        }