public void Drive(CreateTrainPlaner driveTest)
 {
     StartEngine(this);
     CrossControll(this);
     ArrivingMidStation(this);
     ArrivingEndStation(this);
 }
示例#2
0
        public static void ArrivingMidStation(CreateTrainPlaner train)
        {
            bool   check = false;
            string station;

            while (check == false)
            {
                if (train.trainSchedules[1].arrivalTime == timer.ToString())
                {
                    lock (_lock)
                    {
                        station = stationList.Where(p => p.id == train.trainSchedules[1].stationId).ToList().Select(p => p.stationName).First();
                        Random rnd    = new Random();
                        int    random = rnd.Next(0, train.passengers.Count);
                        Console.WriteLine($"{train.train.name} arrived to {station} and {random} passenger(s) got off the train");
                        train.passengers.RemoveRange(0, random);
                        while (check == false)
                        {
                            if (train.trainSchedules[1].departureTime == timer.ToString())
                            {
                                station = stationList.Where(p => p.id == train.trainSchedules[1].stationId).ToList().Select(p => p.stationName).First();
                                Console.WriteLine($"{train.train.name} leaving {station}");
                                check = true;
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public static void Main(string[] args)
        {
            CreateDatabase();

            var trainPlaner1 = new TrainPlaner(trainList, 2).FollowSchedule(scheduleList).AddPassengers(passengerList).CrossoverControll();
            var trainPlaner2 = new TrainPlaner(trainList, 3).FollowSchedule(scheduleList).AddPassengers(passengerList).CrossoverControll();

            CreateTrainPlaner testTrainPlaner1 = new CreateTrainPlaner(trainPlaner1);
            CreateTrainPlaner testTrainPlaner2 = new CreateTrainPlaner(trainPlaner2);

            StartTimer(testTrainPlaner1, testTrainPlaner2);
        }
示例#4
0
        public static void CrossControll(CreateTrainPlaner train)
        {
            bool check = false;

            while (check == false)
            {
                if (train.crossOver[0] == timer)
                {
                    Console.WriteLine($"{train.train.name} closing in to crossroad, closing gate");
                    Thread.Sleep(250);
                }
                if (train.crossOver[1] == timer)
                {
                    Console.WriteLine($"{train.train.name} passed by crossroad, open gate");
                    Thread.Sleep(250);
                    check = true;
                }
            }
        }
示例#5
0
        public static void ArrivingEndStation(CreateTrainPlaner train)
        {
            bool   check = false;
            string station;

            while (check == false)
            {
                if (TimeSpan.Parse(train.trainSchedules[2].arrivalTime).Subtract(TimeSpan.FromMinutes(3)) == timer)
                {
                    if (train.trainSchedules[2].stationId == stationList[2].id)
                    {
                        Console.WriteLine($"{train.train.name} will arrive to {stationList[2].stationName} in 3 minutes, setting switch to left");
                        while (check == false)
                        {
                            if (train.trainSchedules[2].arrivalTime == timer.ToString())
                            {
                                station = stationList.Where(p => p.id == train.trainSchedules[2].stationId).ToList().Select(p => p.stationName).First();
                                Console.WriteLine($"{train.train.name} arrived to its end station {station} and {train.passengers.Count} passenger(s) got off the train");
                                check = true;
                            }
                        }
                    }
                    if (train.trainSchedules[2].stationId == stationList[0].id)
                    {
                        Console.WriteLine($"{train.train.name} will arrive to {stationList[0].stationName} in 3 minutes, setting switch to left");
                        while (check == false)
                        {
                            if (train.trainSchedules[2].arrivalTime == timer.ToString())
                            {
                                station = stationList.Where(p => p.id == train.trainSchedules[2].stationId).ToList().Select(p => p.stationName).First();
                                Console.WriteLine($"{train.train.name} arrived to its end station {station} and {train.passengers.Count} passenger(s) got off the train");
                                check = true;
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        public static void StartTimer(CreateTrainPlaner train1, CreateTrainPlaner train2)
        {
            TimeSpan addMin = TimeSpan.FromMinutes(1);

            timer = new TimeSpan(10, 15, 00);
            for (int i = 0; i < 62; i++)
            {
                if (train1.trainSchedules[0].departureTime == timer.ToString())
                {
                    train1.trainThread      = new Thread(() => train1.Drive(train1));
                    train1.trainThread.Name = "Train1";
                    train1.trainThread.Start();
                }
                if (train2.trainSchedules[0].departureTime == timer.ToString())
                {
                    train2.trainThread      = new Thread(() => train2.Drive(train2));
                    train2.trainThread.Name = "Train2";
                    train2.trainThread.Start();
                }
                timer += addMin;
                Thread.Sleep(200);
            }
        }
示例#7
0
        public static void StartEngine(CreateTrainPlaner train)
        {
            string station = stationList.Where(p => p.id == train.trainSchedules[0].stationId).ToList().Select(p => p.stationName).First();

            Console.WriteLine($"{train.train.name} leaving {station} and {train.passengers.Count} passanger(s) aboard the train, setting switch to right");
        }