Ejemplo n.º 1
0
        /// <summary>
        /// Sort and returns a list of events based on the distance between the event and the coodinates (Accending order)
        /// </summary>
        /// <param name="events">The list of events to sort</param>
        /// <param name="coodinates">The specific coodinate</param>
        /// <returns></returns>
        public static List <Event> SortedEventsInDistance(List <Event> events, Vector2 coodinates)
        {
            List <Event> _events = events; //Copy the list

            //Sort list by comparing distance between inputed location and each event's location
            _events.Sort(
                delegate(Event e1, Event e2)
            {
                //Compare the distance (lower first)
                int compare = Mathc.Distance(e1.Location, coodinates).CompareTo(Mathc.Distance(e2.Location, coodinates));

                //If distance are the same, compare their lowest ticket price (lower first)
                if (compare == 0)
                {
                    //If both of them have 0 tickets, return 0 (No change in order)
                    if (e1.Tickets.Count < 1 && e2.Tickets.Count < 1)
                    {
                        compare = 0;
                    }
                    //If e1 has 0 tickets, return 1 (e1 increase the index)
                    else if (e1.Tickets.Count < 1)
                    {
                        compare = 1;
                    }
                    //If e2 has 0 tickets, return -1 (e1 reduce the index)
                    else if (e2.Tickets.Count < 1)
                    {
                        compare = -1;
                    }
                    //If e1 and e2 both have tickets, compare their ticket price
                    else
                    {
                        compare = SortedTicketsInPrice(e1.Tickets)[0].Price.CompareTo(SortedTicketsInPrice(e2.Tickets)[0].Price);
                    }
                }
                return(compare);
            });
            return(_events);
        }