예제 #1
0
        public static string buildTrack(string state)
        {
            if (state == "startTrack")
            {
                selectedStationForSource = CurrentStations.Find(i => i.Name == Homepage.namingTextBox.Text.Trim());
                if (string.IsNullOrEmpty(Homepage.namingTextBox.Text.Trim()))
                {
                    Homepage.ConsoleTextBox.Text = "Sorry! You have to pick a Station";
                    return(state);
                }
                if (selectedStationForSource == null)
                {
                    Homepage.ConsoleTextBox.Text = "We couldn't find a Station named " + Homepage.namingTextBox.Text.Trim();
                    return(state);
                }

                Homepage.ConsoleTextBox.Text = "Alright, we have set the start of the track to " + Homepage.namingTextBox.Text.Trim() + " now, where do you want it to end?";
                Homepage.namingTextBox.Text  = null;
                return("endTrack");
            }
            if (state == "endTrack")
            {
                Homepage.ConsoleTextBox.Text = "we made it to endTrack";
                if (string.IsNullOrEmpty(Homepage.namingTextBox.Text.Trim()))
                {
                    Homepage.ConsoleTextBox.Text = "Sorry! You have to pick a Station";
                    return(state);
                }
                var selectedStationforDestination = CurrentStations.Find(i => i.Name == Homepage.namingTextBox.Text.Trim());
                if (selectedStationforDestination == null)
                {
                    Homepage.ConsoleTextBox.Text = "We couldn't find a Station named " + Homepage.namingTextBox.Text.Trim();
                    return(state);
                }
                Homepage.ConsoleTextBox.Text = "You picked Station " + selectedStationforDestination.Name;
                Homepage.namingTextBox.Text  = null;
                if (selectedStationforDestination == selectedStationForSource)
                {
                    Homepage.ConsoleTextBox.Text = "Sorry, you can't make a looped track. Transaction cancelled.";
                    Bank.CurrentMoney           += Bank.costOfTrack;
                    Bank.updateMoneyBox();
                    return(null);
                }
                Homepage.ConsoleTextBox.Text = "Alright, we have set the track for you!";
                CurrentTracks.Add(new Track(selectedStationForSource, selectedStationforDestination));
                state = null;
                Train.updateTrainInfoBox();
                Station.updateStationInfoBox();
            }
            return(state);
        }
예제 #2
0
 public void AddTrack(TrackData trackData)
 {
     //Check if TrackData with given tag already exists.
     if (CurrentTracks.Exists(x => x.Tag == trackData.Tag))
     {
         //Find index of existing data.
         int index = CurrentTracks.FindIndex(x => x.Tag == trackData.Tag);
         //replace existing data with new data.
         CurrentTracks[index] = trackData;
     }
     else
     {
         //Add trackData.
         CurrentTracks.Add(trackData);
     }
 }