示例#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 static string moveTrain(string state)
 {
     if (state == "MoveTrain")
     {
         if (string.IsNullOrEmpty(Homepage.namingTextBox.Text.Trim()))
         {
             Homepage.ConsoleTextBox.Text = "Sorry! You have to pick a Train";
             return(state);
         }
         TrainForMove = CurrentTrains.Find(i => i.Name == Homepage.namingTextBox.Text.Trim());
         if (TrainForMove == null)
         {
             Homepage.ConsoleTextBox.Text = "We couldn't find a train named " + Homepage.namingTextBox.Text.Trim();
             return(null);
         }
         Homepage.namingTextBox.Text  = null;
         Homepage.ConsoleTextBox.Text = "Alright, we found your Train! It is at station " + TrainForMove.TrainCurrentLocation.Name + " .Go ahead and add any packages or press 'Yes' to continue.";
         state = "PackageManagement";
         foreach (Package i in TrainForMove.TrainCurrentLocation.PackagesWaiting)
         {
             Homepage.packageSelectionDropDown.Items.Add(i.PackageType + "-" + i.PackageValue + "," + i.PackageDestinationStation.Name);
         }
         return(state);
     }
     else if (state == "MoveTrainDestination")
     {
         if (string.IsNullOrEmpty(Homepage.namingTextBox.Text.Trim()))
         {
             Homepage.ConsoleTextBox.Text += "Sorry! You have to pick a Station";
             return(state);
         }
         var selectedStationForMoving = CurrentStations.Find(i => i.Name == Homepage.namingTextBox.Text.Trim());
         if (selectedStationForMoving == null)
         {
             Homepage.ConsoleTextBox.Text = "We couldn't find a Station named " + Homepage.namingTextBox.Text.Trim();
             return(state);
         }
         var trackExists = CurrentTracks.Find(i => i.sourceStation == TrainForMove.TrainCurrentLocation && i.destinationStation == selectedStationForMoving);
         if (trackExists == null)
         {
             Homepage.ConsoleTextBox.Text = "Sorry, there is no track there. Transaction cancelled.";
             Homepage.namingTextBox.Text  = null;
             return(null);
         }
         TrainForMove.TrainCurrentLocation = selectedStationForMoving;
         Homepage.ConsoleTextBox.Text      = "You have moved!";
         Homepage.namingTextBox.Text       = null;
         Train.updateTrainInfoBox();
         Station.updateStationInfoBox();
         Homepage.packageSelectionDropDown.Items.Clear();
         Homepage.packageSelectionDropDown.SelectedItem = null;
         foreach (Package i in TrainForMove.Holding)
         {
             if (i.PackageDestinationStation == TrainForMove.TrainCurrentLocation)
             {
                 Bank.CurrentMoney           += i.PackageValue;
                 Homepage.ConsoleTextBox.Text = "Awesome! Packages have been successfully delivered!";
             }
         }
         TrainForMove.Holding.RemoveAll(i => i.PackageDestinationStation == TrainForMove.TrainCurrentLocation);
         Bank.updateMoneyBox();
         Train.updateTrainInfoBox();
         Station.updateStationInfoBox();
         state = null;
     }
     return(state);
 }