forked from Sean-Bradley/Design-Patterns-In-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaretaker.py
More file actions
24 lines (19 loc) · 737 Bytes
/
caretaker.py
File metadata and controls
24 lines (19 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"The Save/Restore Game functionality"
class CareTaker():
"Guardian. Provides a narrow interface to the mementos"
def __init__(self, originator):
self._originator = originator
self._mementos = []
def save(self):
"Store a new Memento of the Characters current state"
print("CareTaker: Game Save")
memento = self._originator.memento
self._mementos.append(memento)
def restore(self, index):
"""
Replace the Characters current attributes with the state
stored in the saved Memento
"""
print("CareTaker: Restoring Characters attributes from Memento")
memento = self._mementos[index]
self._originator.memento = memento