-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.py
More file actions
47 lines (38 loc) · 986 Bytes
/
commands.py
File metadata and controls
47 lines (38 loc) · 986 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import printing
class Command:
def execute(self):
raise NotImplementedError
class Condition:
pass
class TrueCond(Condition):
def eval(self):
return True
class InCond(Condition):
def __init__(self, dic, key, val):
self.dic = dic
self.key = key
self.val = val
def eval(self):
try:
if self.dic[self.key] == self.val:
return True
except KeyError:
return False
class KillCmd(Command):
def __init__(self, str):
self.str = str
def execute(self):
print("Oh no! You've locked yourself out!")
exit(1)
class NullCmd(Command):
def __init__(self):
pass
def execute(self):
pass
class AddNavCmd(Command):
def __init__(self, origin, dest, direction):
self.origin = origin
self.dest = dest
self.direction = direction
def execute(self):
self.origin.add_nav(self.direction, self.dest)