Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            ClockSimulator sim = new ClockSimulator(100, 60);

            sim.StartClock();
            Controller controller = new Controller();

            ObjectBuilder.BuildAll();

            controller.OperateTrain(ObjectBuilder.Trains[1]);
            controller.OperateTrain(ObjectBuilder.Trains[2]);
        }
Ejemplo n.º 2
0
        public void Start(Train train, List <TimeTable> timeTable, ClockSimulator clockSim)
        {
            timeTable = timeTable.Where(x => x.TrainID == train.ID).ToList();

            while (timeTable.Any())
            {
                if (!train.IsRunning() && timeTable[0].DepartureTime.TimeOfDay <= clockSim.GetDateTime().TimeOfDay)
                {
                    train.StartTrain();
                    Console.WriteLine($"Log {clockSim.TimeToString()} : {train.Name} : departing from {ObjectBuilder.Stations.Find(s => s.ID == timeTable[0].DepStationID).Name} station");
                }
                if (train.IsRunning() && timeTable[0].ArrivalTime.TimeOfDay <= clockSim.GetDateTime().TimeOfDay)
                {
                    train.StopTrain();
                    Console.WriteLine($"Log {clockSim.TimeToString()} : {train.Name} : arriving at {ObjectBuilder.Stations.Find(s => s.ID == timeTable[0].ArrStationID).Name} station");
                    timeTable.Remove(timeTable[0]);
                }
            }
        }