-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport.py
75 lines (58 loc) · 1.97 KB
/
transport.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Vehicle Selection - either a CAR or a BIKE"""
import itertools
class State(object):
def selectNextVehicle(self):
"""
Cycling through vehicles in a particular state
"""
print("[+] Selecting vehicle... Vehicle is", next(self.vehicles), " - ", self.name)
# State no. 1
class BikeState(State):
def __init__(self, transport):
self.transport = transport
self.l = ["TVS", "Yamaha", "Duke", "Activa", "Bullet"]
self.vehicles = itertools.cycle(self.l)
self.name = "BIKE"
def toggle_wheels(self):
"""
Change state to CARS state
"""
print("[*] Switching to CARS")
self.transport.state = self.transport.carState
def listVehicles(self):
"""
List vehicles available in BIKE state
"""
for i in range(len(self.l)):
print(str(i+1) + ") " + self.l[i])
# State no. 2
class CarState(State):
def __init__(self, transport):
self.transport = transport
self.l = ["Swift Dzire", "Verna", "Renault Kwid", "Nano", "Innova"]
self.vehicles = itertools.cycle(self.l)
self.name = "CAR"
def toggle_wheels(self):
"""
Change state to BIKE state
"""
print("[*] Switching to BIKES")
self.transport.state = self.transport.bikeState
def listVehicles(self):
"""
List vehicles available in CARS state
"""
for i in range(len(self.l)):
print(str(i+1) + ") " + self.l[i])
class Transport(object):
def __init__(self):
self.bikeState = BikeState(self)
self.carState = CarState(self)
# Set default state to BIKES
self.state = self.bikeState
def toggle_wheels(self):
self.state.toggle_wheels()
def selectNextVehicle(self):
self.state.selectNextVehicle()
def listVehicles(self):
self.state.listVehicles()