public Elevator(int id_, Column column_) { ID = id_; Column = column_; Status = "online"; // online|offline Movement = "idle"; // up|down|idle CurrentFloor = 1; FloorDisplay = new FloorDisplay(this); RequestsQueue = new List <Request>(); Door = new ElevatorDoor("closed"); }
// Make elevator go to its scheduled next floor public void GoToNextFloor() { if (CurrentFloor != NextFloor) { if (CurrentFloor > 0) { WriteLine($"Elevator {ID} of Column {Column.ID}, currently at floor {CurrentFloor}, is about to go to floor {NextFloor}..."); } else if (NextFloor < 0) { WriteLine($"Elevator {ID} of Column {Column.ID}, currently at floor B{Math.Abs(CurrentFloor)}, is about to go to floor B{Math.Abs(NextFloor)}..."); } else if (NextFloor > 0) { WriteLine($"Elevator {ID} of Column {Column.ID}, currently at floor B{Math.Abs(CurrentFloor)}, is about to go to floor {NextFloor}..."); } WriteLine("================================================================="); FloorDisplay.DisplayFloor(); // Traverse through the floors while (CurrentFloor != NextFloor) { // Do not display floors that are not part of the column's range if (Movement.ToLower() == "up") { if (CurrentFloor + 1 < Column.LowestFloor) { WriteLine($"\n... Quickly traversing through the floors not in column {Column.ID}'s usual elevator range ...\n");; CurrentFloor = Column.LowestFloor; } else { CurrentFloor++; } } else { if (CurrentFloor - 1 < Column.LowestFloor) { WriteLine($"\n... Quickly traversing through the floors not in column {Column.ID}'s usual elevator range ...\n"); CurrentFloor = OriginFloor; } else { CurrentFloor--; } } FloorDisplay.DisplayFloor(); } WriteLine("================================================================="); if (CurrentFloor > 0) { WriteLine($"Elevator {ID} of Column {Column.ID} has reached its requested floor! It is now at floor {CurrentFloor}"); } else { WriteLine($"Elevator {ID} of Column {Column.ID} has reached its requested floor! It is now at floor B{Math.Abs(CurrentFloor)}"); } } }