Update TestBasedGame.py
This commit is contained in:
parent
7e7a887156
commit
7a2e37ebde
1 changed files with 24 additions and 19 deletions
|
@ -179,26 +179,14 @@ def print_strings(string):
|
||||||
print("[!!!] You hear a loud noise coming from the children's bedroom... better investigate!")
|
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"]):
|
def get_new_state(direction, current_room=system["game"]["current_room"]):
|
||||||
if input_from_user in rooms[current_room]["paths"]:
|
if direction in rooms[current_room]["paths"]:
|
||||||
if rooms[rooms[current_room]["paths"][input_from_user]]["locked"]:
|
if rooms[rooms[current_room]["paths"][direction]]["locked"]:
|
||||||
print_strings(rooms[system["game"]["current_room"]]["paths"][input_from_user] + "_locked")
|
print_strings(rooms[system["game"]["current_room"]]["paths"][direction] + "_locked")
|
||||||
else:
|
else:
|
||||||
system["game"]["current_room"] = rooms[current_room]["paths"][input_from_user]
|
system["game"]["current_room"] = rooms[current_room]["paths"][direction]
|
||||||
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
|
|
||||||
else:
|
else:
|
||||||
print("[Error] Invalid action; please try again.")
|
print("[Move] You can't go that way.")
|
||||||
|
|
||||||
|
|
||||||
def show_status():
|
def show_status():
|
||||||
|
@ -219,7 +207,24 @@ def main():
|
||||||
while system["game"]["completed"] is False:
|
while system["game"]["completed"] is False:
|
||||||
show_status()
|
show_status()
|
||||||
print("What would you like to do?")
|
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"]:
|
if "Greenhouse key" in system["game"]["items"] and rooms["greenhouse"]["locked"]:
|
||||||
rooms["greenhouse"]["locked"] = False
|
rooms["greenhouse"]["locked"] = False
|
||||||
if len(system["game"]["items"]) == 7 and rooms["children_bedroom"]["locked"]:
|
if len(system["game"]["items"]) == 7 and rooms["children_bedroom"]["locked"]:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue