public static void TravelPlannerTest() { //instansierar alla listor och tilldelar dem, vardera returnerade object-värdet. List <Train> trains = Train.GetTrains(); List <Station> stations = Station.GetStations(); List <Passenger> passengers = Passenger.GetPassenger(); List <Schedule> schedules = Schedule.GetSchdules(); List <TrainTrack> trainTracks = TrainTrack.GetTrainTracks(); //(här skulle instanserna av trackobject klasserna kunna vara i framtiden) Console.WriteLine("Starting the Travel Plan"); TravelPlan travelPlan = new TravelPlan(trainTracks, stations, passengers).SetTrain(trains).SetSchedule(schedules).Start(); Console.WriteLine("Press any key to exit"); Console.ReadKey(); Console.Clear(); Console.WriteLine("You Exited"); }
private void StateMachineTrack2(Train train, List <Schedule> trainTimeTableList, TrainTrack track) { switch (train.trainState) { case TrainState.atStartStation: train.PassengersInTrain.AddRange(_stations[0].PassengersInStation); _stations[0].PassengersInStation.Clear(); train.Stop(); var timeStartStation = trainTimeTableList.Where(x => x.StationId == track.StartStationId).FirstOrDefault(); Console.WriteLine("The train " + train.Name + " is at: " + _stations.Where(x => x.ID == track.StartStationId).Single().StationName + " station"); if ((TimeSpan.Parse(timeStartStation.DepartureTime) - globalClock) >= zero) { Console.WriteLine("Train waiting to depart. Departing in : " + (TimeSpan.Parse(timeStartStation.DepartureTime) - globalClock)); } if (globalClock >= TimeSpan.Parse(timeStartStation.DepartureTime)) { Console.WriteLine("Train Departing with " + train.PassengersInTrain.Count + " passengers in train"); train.Start(); train.trainState = TrainState.onWayToSecondSwitch; } break; case TrainState.onWayToSecondSwitch: if (train.DistanceTravelled >= track.Switch2Position) { track.Switch2Left = true; Console.WriteLine("Second Switch is switched to it's left position"); train.trainState = TrainState.onWayToMiddleStation; } break; case TrainState.onWayToMiddleStation: if (train.DistanceTravelled >= track.MiddleStationPosition) { train.trainState = TrainState.atMiddleStation; train.Stop(); var passengerCount = (train.PassengersInTrain.Count / 2); for (int i = 0; i < passengerCount; i++) { _stations[1].PassengersInStation.Add(train.PassengersInTrain.ElementAt(0)); train.PassengersInTrain.RemoveAt(0); } Console.WriteLine("The train has arrived at: " + _stations.Where(x => x.ID == track.MiddleStationId).Single().StationName); Console.WriteLine("Dropped of " + _stations[1].PassengersInStation.Count + " passengers at station"); } break; case TrainState.atMiddleStation: var timeMiddleStation = trainTimeTableList.Where(x => x.StationId == track.MiddleStationId).Single(); if ((TimeSpan.Parse(timeMiddleStation.DepartureTime) - globalClock) >= zero) { Console.WriteLine("Train waiting to depart. Departing in : " + (TimeSpan.Parse(timeMiddleStation.DepartureTime) - globalClock)); } else { Console.WriteLine("Train Departing with " + train.PassengersInTrain.Count + " passengers"); train.Start(); train.trainState = TrainState.onWayToFirstSwitch; } break; case TrainState.onWayToFirstSwitch: if (train.DistanceTravelled >= track.Switch1Position) { track.Switch1Left = false; Console.WriteLine("First Switch is switched to it's right position"); train.trainState = TrainState.onWayToClosingCrossing; } break; case TrainState.onWayToClosingCrossing: if (train.DistanceTravelled >= track.CrossingPosition - 1) { Console.WriteLine("Closing Crossing"); train.trainState = TrainState.onWayToOpenCrossing; } break; case TrainState.onWayToOpenCrossing: if (train.DistanceTravelled >= track.CrossingPosition + 1) { Console.WriteLine("Opening Crossing"); train.trainState = TrainState.onWayToEndStation; } break; case TrainState.onWayToEndStation: if (train.DistanceTravelled >= track.EndStationPosition) { train.trainState = TrainState.atEndStation; train.Stop(); Console.WriteLine("The train has arrived at: " + _stations.Where(x => x.ID == track.EndStationId).Single().StationName); } break; case TrainState.atEndStation: break; } }