self.button_rect.center,
self.button_rect.height // 2,
)
- if self.level in {*self.elevator.call_queue, self.elevator.destination}:
+ if self.elevator.is_dest_or_queued(self.level):
pygame.draw.circle(
surf,
self.BUTTON_GLOW_COLOR,
self.destination = None
self.call_queue = []
- def pop_destination(self, destination):
- while destination in self.call_queue:
- self.call_queue.remove(destination)
- self.destination = destination
-
def pick_destination(self):
"""
If not all doors are closed, bail.
"""
if not all(door.state == door.CLOSED for door in self.doors):
return False
- if not len(self.call_queue) > 0:
- self.pop_destination(self.call_queue.pop(0))
- return True
- return False
+ if len(self.call_queue) == 0:
+ return False
+ destination = self.call_queue.pop(0)
+ while destination in self.call_queue:
+ self.call_queue.remove(destination)
+ self.destination = destination
+ return True
def update(self):
"""
)
self.panel.draw(surf)
- def goto(self, level):
- if self.destination is None and not self.panel.pressed and not (
- self.get_whole_level() == level and self.doors[level].state == Door.OPEN
- ):
- self.call_queue.insert(0, level)
- self.panel.pressed = True
-
def get_whole_level(self):
level, mod = divmod(self.current_level, self.LEVEL_STEPS)
if mod == 0 and self.destination in (None, level):
return level
return None
- def call_from(self, call_level):
- """
- If we are at the destination and the door is open, disregard
- If level is not already a destination, add it to the call_queue
- """
- current = self.get_whole_level()
- if call_level == current and self.doors[call_level].state == Door.OPEN:
- return
- level_queue = {
- current,
- *self.call_queue,
- self.destination,
- }
- if call_level not in level_queue:
- self.call_queue.append(call_level)
- elif call_level == current:
- self.doors[call_level].open()
+ def open_if_there(self, level):
+ if self.get_whole_level() == level and self.doors[level].state != Door.OPEN:
+ self.doors[level].open()
+ return True
+ return False
+
+ def goto(self, level):
+ if (
+ not self.open_if_there(level)
+ and self.destination is None
+ and not self.panel.pressed
+ ):
+ self.call_queue.insert(0, level)
+ self.panel.pressed = True
+
+ def is_dest_or_queued(self, level):
+ return level in {self.destination, *self.call_queue}
+
+ def call_from(self, level):
+ if not self.open_if_there(level) and not self.is_dest_or_queued(level):
+ self.call_queue.append(level)
def open(self):
"""