public TrackDescription ParseTrackDescription(List <string> track)
        {
            TrackDescription trackDescription = new TrackDescription();

            Coordinate  startPosition    = FindStart(track);
            int         distance         = 0;
            List <char> trackParts       = new List <char>();
            int         currentStationId = 0;

            for (int i = 0; i < track[startPosition.LinePosition].Length; i++)
            {
                char symbol = track[startPosition.LinePosition][i];

                // *[1]-------[3]
                // *[1]---=--------[2]-------------[3]

                if (char.IsDigit(symbol))
                {
                    int stationId = int.Parse(symbol.ToString());
                    if (currentStationId == 0)
                    {
                        currentStationId = stationId;
                    }
                    else
                    {
                        var stationConnection = new StationConnection(currentStationId, stationId, distance, trackParts);
                        trackDescription.StationConnections.Add(stationConnection);

                        // Reset values
                        currentStationId = stationId;
                        distance         = 0;
                        trackParts       = new List <char>();
                    }
                }
                else
                {
                    switch (symbol)
                    {
                    case '-':
                        distance++;
                        break;

                    case '=':
                        trackParts.Add(symbol);
                        break;

                    default:
                        break;
                    }
                }
            }

            return(trackDescription);
        }
Exemplo n.º 2
0
        public TravelPlan(List <TravelPlanData> travelPlanDatas, TrackDescription trackDescription)
        {
            TrainsNearLevelCrossing = new List <int>();
            this.travelPlanDatas    = travelPlanDatas;
            TrackDescription        = trackDescription;
            Stations = FileIO.LoadStations();
            Trains   = FileIO.ReadTrainInfo("Data/trains.txt");

            simulationThread = new Thread(Simulate);
            simulationThread.Start();
        }
 public ITravelPlanner AddTrack(TrackDescription trackDescription)
 {
     TrackDescription = trackDescription;
     return(this);
 }