コード例 #1
0
 public Direction NextDirection(ElevatorWaypoint nextWaypoint)
 {
     if (this.CurrentFloor > nextWaypoint.DestinationFloor)
     {
         return(Direction.DOWN);
     }
     else if (this.CurrentFloor < nextWaypoint.DestinationFloor)
     {
         return(Direction.UP);
     }
     return(Direction.NONE);
 }
コード例 #2
0
        private void _addWaypoint(ElevatorWaypoint newWaypoint, List <ElevatorWaypoint> waypoints)
        {
            if (this.IsRelocating)
            {
                this.CancelRelocation();
            }

            if (waypoints.Count() == 0 || newWaypoint.DestinationFloor == this.CurrentFloor && newWaypoint.WaypointType != WaypointType.PICK_UP)
            {
                waypoints.Insert(0, newWaypoint);
                return;
            }

            if (newWaypoint.DestinationFloor < this.CurrentFloor)
            {
                uint last = this.CurrentFloor;
                // Make sure that all other waypoints go down
                for (int i = 0; i < waypoints.Count(); i++)
                {
                    if (last < waypoints[i].DestinationFloor)
                    {
                        throw new InvalidElevatorStateException("The Waypoints list is no longer in order");
                    }

                    if (last >= newWaypoint.DestinationFloor && waypoints[i].DestinationFloor < newWaypoint.DestinationFloor)
                    {
                        waypoints.Insert(i, newWaypoint);
                        return;
                    }

                    last = waypoints[i].DestinationFloor;
                }

                waypoints.Add(newWaypoint);
                return;
            }

            if (newWaypoint.DestinationFloor > this.CurrentFloor)
            {
                uint last = this.CurrentFloor;
                // Make sure that all other waypoints go down
                for (int i = 0; i < waypoints.Count(); i++)
                {
                    if (last > waypoints[i].DestinationFloor)
                    {
                        throw new InvalidElevatorStateException("The Waypoints list is no longer in order");
                    }

                    if (last <= newWaypoint.DestinationFloor && waypoints[i].DestinationFloor > newWaypoint.DestinationFloor)
                    {
                        waypoints.Insert(i, newWaypoint);
                        return;
                    }

                    last = waypoints[i].DestinationFloor;
                }

                waypoints.Add(newWaypoint);
                return;
            }

            if (this.NextDirection(new ElevatorWaypoint(newWaypoint.AssociatedNext, WaypointType.DROP_OFF)) == this.Direction || this.Direction == Direction.NONE)
            {
                waypoints.Insert(0, newWaypoint);
            }
            else
            {
                throw new InvalidElevatorStateException("Something went wrong while adding a waypoint");
            }
        }
コード例 #3
0
 /// <summary>
 /// Add a new waypoint to the list of waypoint
 /// </summary>
 /// <param name="newWaypoint">The new waypoint to be added</param>
 public void AddWaypoint(ElevatorWaypoint newWaypoint)
 {
     _addWaypoint(newWaypoint, this.Waypoints);
 }