Skip to content

Commit

Permalink
added get verb
Browse files Browse the repository at this point in the history
  • Loading branch information
petmas2008 committed Nov 21, 2020
1 parent f3e5cbb commit 624c031
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion adventure/lib/adventurelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class UnknownObjectError(Exception):
pass

class Adventure(base.Base):


verbs = {"go", "get", "drop"}
syns = {"run" : "go", "move" : "go", "grab" : "get"}

def __init__(self, name, player_name):
"""Set up an adventure from details in a spreadsheet
"""
Expand All @@ -30,6 +33,13 @@ def __init__(self, name, player_name):
self.rooms = {}
self.inventory = {}

def get_verb(self, word):
found_word = self.syns.get(word, word)
if found_word in self.verbs:
return found_word
else:
raise RuntimeError("No hablo espanol")

def load_initial_game_from_spreadsheet(self, filepath=None):
"""Load the rooms, layout and items from a spreadsheet
"""
Expand Down Expand Up @@ -110,3 +120,7 @@ def handle_command(self, type, command):
else:
raise RuntimeError("Unknown command type %s" % type)

if __name__ == "__main__":
a = Adventure("Peter", "house")
print(a.get_verb("go"))
print(a.get_verb("move"))

0 comments on commit 624c031

Please sign in to comment.