public bool AddBusStop(BusStop busStop) { var lastStop = LastVisitedBusStop(); if (lastStop == null) { VisitedBusStops.Add(busStop); DistanceCovered += HelperMethods.Distance(busStop.X, busStop.Y, BusParameters.School.X, BusParameters.School.Y); SeatsTaken += busStop.SeatsTaken; return(true); } var distanceToBusStop = HelperMethods.Distance(busStop.X, busStop.Y, lastStop.X, lastStop.Y); var distanceToSchool = HelperMethods.Distance(lastStop.X, lastStop.Y, BusParameters.School.X, BusParameters.School.Y); if (SeatsTaken + busStop.SeatsTaken <= BusParameters.BusCapacity && distanceToBusStop <= distanceToSchool) { VisitedBusStops.Add(busStop); DistanceCovered += distanceToBusStop; SeatsTaken += busStop.SeatsTaken; return(true); } return(false); }
public BusStop LastVisitedBusStop() { return(VisitedBusStops.LastOrDefault()); }