diff --git a/TestBasedGame.py b/TestBasedGame.py index af1334f..402527e 100644 --- a/TestBasedGame.py +++ b/TestBasedGame.py @@ -179,26 +179,14 @@ def print_strings(string): print("[!!!] You hear a loud noise coming from the children's bedroom... better investigate!") -def get_new_state(input_from_user, current_room=system["game"]["current_room"]): - if input_from_user in rooms[current_room]["paths"]: - if rooms[rooms[current_room]["paths"][input_from_user]]["locked"]: - print_strings(rooms[system["game"]["current_room"]]["paths"][input_from_user] + "_locked") +def get_new_state(direction, current_room=system["game"]["current_room"]): + if direction in rooms[current_room]["paths"]: + if rooms[rooms[current_room]["paths"][direction]]["locked"]: + print_strings(rooms[system["game"]["current_room"]]["paths"][direction] + "_locked") else: - system["game"]["current_room"] = rooms[current_room]["paths"][input_from_user] - elif input_from_user == "search": - if get_item(system["game"]["current_room"]): - print("[Search] You found a", rooms[current_room]["item_name"], rooms[current_room]["item_location"] + "!") - system["game"]["items"].append(rooms[system["game"]["current_room"]]["item_name"]) - else: - print("[Search] You found nothing.") - elif input_from_user == "items": - list_items() - elif input_from_user == "help": - show_instructions() - elif input_from_user == "quit" or input_from_user == "exit": - system["game"]["completed"] = True + system["game"]["current_room"] = rooms[current_room]["paths"][direction] else: - print("[Error] Invalid action; please try again.") + print("[Move] You can't go that way.") def show_status(): @@ -219,7 +207,24 @@ def main(): while system["game"]["completed"] is False: show_status() print("What would you like to do?") - get_new_state(input('> ').lower(), system["game"]["current_room"]) + user_action = (input('> ').lower()) + if user_action == "search": + if get_item(system["game"]["current_room"]): + print("[Search] You found a", rooms[system["game"]["current_room"]]["item_name"], + rooms[system["game"]["current_room"]]["item_location"] + "!") + system["game"]["items"].append(rooms[system["game"]["current_room"]]["item_name"]) + else: + print("[Search] You found nothing.") + elif user_action == "items": + list_items() + elif user_action == "help": + show_instructions() + elif user_action == "quit" or user_action == "exit": + system["game"]["completed"] = True + elif user_action in ['west', 'north', 'south', 'east']: + get_new_state(user_action, system["game"]["current_room"]) + else: + print("[Error] Invalid action; please try again.") if "Greenhouse key" in system["game"]["items"] and rooms["greenhouse"]["locked"]: rooms["greenhouse"]["locked"] = False if len(system["game"]["items"]) == 7 and rooms["children_bedroom"]["locked"]: