-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmachine.py
More file actions
40 lines (35 loc) · 1.14 KB
/
machine.py
File metadata and controls
40 lines (35 loc) · 1.14 KB
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
"""
machine.py
"""
from state import *
class GumballMachine:
def __init__(self, count):
self.count = count
self.has_quarter_state = HasQuarterState()
self.no_quarter_state = NoQuarterState()
self.sold_state = SoldState()
self.sold_out_state = SoldOutState()
self.state = self.no_quarter_state if self.count > 0 else self.sold_out_state
def insert_quarter(self):
self.state.insert_quarter(self)
def eject_quarter(self):
self.state.eject_quarter(self)
def turn_crank(self):
self.state.turn_crank(self)
self.state.dispense(self)
def set_state(self, state):
self.state = state
def get_has_quarter_state(self):
return self.has_quarter_state
def get_no_quarter_state(self):
return self.no_quarter_state
def get_sold_state(self):
return self.sold_state
def get_sold_out_state(self):
return self.sold_out_state
def get_count(self):
return self.count
def release_ball(self):
print("A gumball comes rolling out the slot...")
if self.count > 0:
self.count = self.count - 1