Пример #1
0
        public static void addEvent(Event happening)
        {
            foreach (Event oud in list)
            {
                if ((happening.Subject != null) && oud.Subject != null && (happening.Name == oud.Name) && (happening.Subject.TramNo == oud.Subject.TramNo))
                {
                    Console.WriteLine("Duplicate event " + happening.Name + " detected at station " + happening.Place.Name + " for tram " + happening.Subject.TramNo.ToString());
                    Console.ReadLine(); Sim.EmergencyExit();
                }
                if ((happening.Subject != null) && oud.Subject != null && (happening.Subject.TramNo == oud.Subject.TramNo))
                {
                    Console.WriteLine("Dual event found for tram" + happening.Subject.TramNo.ToString() + ": " + happening.Name + " at " + happening.Place.Name + "  and " + oud.Name + " at " + oud.Place.Name);
                    Console.ReadLine(); Sim.EmergencyExit();
                }
            }


            int time = happening.ETime;

            for (int i = 0; i < list.Count(); i++)
            {
                if (time < list[i].ETime)
                {
                    list.Insert(i, happening);
                    if (Simulation.EXPLICIT)
                    {
                        Console.WriteLine("Inserted event " + happening.Name + " at station " + happening.Place.Name + " for time " + happening.ETime.ToString() + " at time " + Time.Now().ToString());
                    }
                    return;
                }
                else if (time == list[i].ETime && happening.Priority > list[i].Priority)
                {
                    list.Insert(i, happening);
                    if (Simulation.EXPLICIT)
                    {
                        Console.WriteLine("Inserted event " + happening.Name + " at station " + happening.Place.Name + " for time " + happening.ETime.ToString() + " at time " + Time.Now().ToString());
                    }
                    return;
                }
            }
            list.Add(happening);
        }
Пример #2
0
        /*
         *  In addition to moving the tram: logs some data on tram activity.
         */
        private void moveTo(iHasRails place)
        {
            if (Simulation.EXPLICIT)
            {
                Console.WriteLine("Moving tram " + TramNo.ToString() + " from " + Position.Name + " to " + place.Name);
            }

            if (!place.AddTram(this))
            {
                Console.WriteLine("Error trying to move Tram" + TramNo.ToString() + " to station " + place.Name);
                Console.ReadLine(); Sim.EmergencyExit();
            }
            Position.RemoveTram(this);
            logger.WriteLine(Time.Now().ToString() + " , " + Position.Name + " , " + place.Name);
            tramActivitylog.WriteLine(Time.Now().ToString() + " , Move , " + Position.Name + " , " + place.Name);
            Position = place;
        }
        public bool AddTram(Tram tram)
        {
            int pos = firstOpenPos();

            if (pos != -1)
            {
                Spaces[pos] = tram;
                return(true);
            }

            Console.WriteLine("Failure to add tram to station " + Name + ". Ending simulation");
            Console.ReadLine(); Sim.EmergencyExit();;
            return(false);
        }