Esempio n. 1
0
        public IController StartTrain(Train train)
        {
            var stations = stopStationsT3;

            if (train.ID == 2)
            {
                stations = stopStationsT2;
            }

            var endStation = stations.Last();

            for (int i = 0; i < specificTrainTimeTable.Count - 1; i++)
            {
                TimeSpan addOneMinute = TimeSpan.FromMinutes(1);
                Departure = DateTime.Parse(specificTrainTimeTable[i].DepartureTime);
                Arrival   = DateTime.Parse(specificTrainTimeTable[i + 1].ArrivalTime);

                for (int j = 0; j < stations.Count; j++)
                {
                    if (stations[j].ID == specificTrainTimeTable[i].StationID)
                    {
                        if (specificTrainTimeTable[i].ArrivalTime == "00:00")
                        {
                            Console.WriteLine($"Train { train.Name } is leaving from { stations[i].Name } at { specificTrainTimeTable[i].DepartureTime }");
                            Console.WriteLine();
                        }

                        else if (specificTrainTimeTable[i].ArrivalTime != "00:00")
                        {
                            Console.WriteLine(train.Name);
                            Console.WriteLine($"Arrived at { stations[j].Name } at { specificTrainTimeTable[i].ArrivalTime }");
                            Console.WriteLine($"Next departure: { specificTrainTimeTable[i].DepartureTime }");
                            Console.WriteLine();
                        }

                        else if (stations[j].EndStation == true)
                        {
                            Console.WriteLine($"{ stations[j].Name } is the final destination for { train.Name }");
                            Console.WriteLine($"Arrived at { specificTrainTimeTable[i].ArrivalTime }");
                            Console.WriteLine();
                        }

                        if (i == 1)
                        {
                            Thread.Sleep(2000);
                        }

                        while (Departure < Arrival)
                        {
                            Console.WriteLine($"{train.Name} says: Choo choo { Departure:HH:mm}");
                            Departure += addOneMinute;
                            Arrival.AddMinutes(addOneMinute.Minutes);
                            Thread.Sleep(200);
                        }
                    }
                }

                Console.WriteLine($"{train.Name} Arrival Time: { Arrival:HH:mm}");
                Console.WriteLine();
            }

            Console.WriteLine($"Arrived at { endStation.Name } which is");
            Console.WriteLine($"{ train.Name } 's final destination.");
            Console.WriteLine();

            return(this);
        }
Esempio n. 2
0
        public IController FollowTimeTable(Train train)
        {
            specificTrainTimeTable = times.Where(t => t.TrainID == train.ID).ToList();

            return(this);
        }