-
Notifications
You must be signed in to change notification settings - Fork 0
/
lane.py
38 lines (31 loc) · 1.12 KB
/
lane.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from objectBase import ObjectBase
class Lane(ObjectBase):
def __init__(self, id_=None, parent_object=None, lights=None):
super().__init__(id_=id_, parent_object=parent_object)
self.queue = []
self.lights = lights
def is_incoming(self):
return (False if self.outgoing else True)
def add_to_queue(self, object_):
"""Method adds object (car) to queue"""
self.queue.append(object_)
def get_first_car(self):
"""Method returns first car from queue or None if not available."""
try:
car = self.queue[0]
return car
except IndexError:
return None
def get_lights(self):
"""Method returns traffic lights for current lane"""
return self.lights
def get_queue(self):
"""Method returns all cars currently awaiting in queue"""
return self.queue
def remove_first_car(self):
"""Method removes and returns first car from queue or None if not available."""
try:
car = self.queue.pop(0)
return car
except IndexError:
return None