-
Notifications
You must be signed in to change notification settings - Fork 0
/
car.py
61 lines (50 loc) · 1.56 KB
/
car.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# car class file
class Car(object):
ride_queue = None
counter = 1
time = 0
def __init__(self):
self.pos = (0, 0)
self.ride = None
self.riding = False
self.time_remaining = 0
self.finish = False
self.is_moving = False
self.id = Car.counter
Car.counter += 1
@classmethod
def initialise_ride_queue(cls, queue):
cls.ride_queue = queue
def get_ride_queue(self):
return Car.ride_queue
def step(self):
# check if finished
if self.finish is True:
return
# find ride
if Car.ride_queue.ride_empty():
self.finished = True
return
self.ride = Car.ride_queue.give_ride(self.pos[0], self.pos[1], self.id)
if self.ride is not None:
self.time_remaining = self.ride.distance2start(self.pos)
else:
self.is_moving = False
# check if ride
if self.ride is not None:
self.ride_step()
def ride_step(self):
# if not got ride count down time remaining to pick up
if self.riding is False:
self.time_remaining -= 1
if self.time_remaining == 0:
self.riding = True
self.pos = self.ride.start_pos
self.time_remaining = self.ride.ride_length
# if got ride
else:
self.time_remaining -= 1
if self.time_remaining == 0:
self.ride = None
self.riding = False
self.pos = self.ride.end_pos