def run_room(player_inventory): # Let the user know what the room looks like print(room7_description) # valid commands for this room commands = ["go", "take", "drop", "use", "examine", "status", "help"] no_args = ["examine", "status", "help"] # nonsense room number, # In the loop below the user should eventually ask to "go" somewhere. # If they give you a valid direction then set next_room to that value next_room = -1 done_with_room = False while not done_with_room: # Examine the response and decide what to do response = utils.ask_command("What do you want to do?", commands, no_args) the_command = response[0] # now deal with the command if the_command == 'go': go_where = response[1].lower() if go_where == 'east': next_room = 8 done_with_room = True elif go_where == 'north': if utils.has_a(player_inventory, 'golden goblet') == True: print("The door is slammed shut") else: next_room = 2 done_with_room = True else: print('You cannot go:', go_where) elif the_command == 'take': response = utils.scrub_response(response) take_what = response[1] utils.take_item(player_inventory, r7_inventory, take_what) if take_what == 'golden goblet': print("The door suddenly slams to the north!") elif the_command == 'drop': response = utils.scrub_response(response) drop_what = response[1] utils.drop_item(player_inventory, r7_inventory, drop_what) if drop_what == 'golden goblet': print("The door to the north swings back open!") elif the_command == 'status': utils.player_status(player_inventory) utils.room_status(r7_inventory) elif the_command == 'examine': print(room7_description) elif the_command == 'help': utils.player_help() else: print("The command:", the_command, "has not been implemented in Room 7") # END of WHILE LOOP return next_room
def run_room(player_inventory): # Let the user know what the room looks like print(room5_description) # valid commands for this room commands = ["go", "take", "drop", "use", "examine", "status", "help"] no_args = ["examine", "status", "help"] # nonsense room number, # In the loop below the user should eventually ask to "go" somewhere. # If they give you a valid direction then set next_room to that value next_room = -1 done_with_room = False while not done_with_room: # Examine the response and decide what to do response = utils.ask_command("What do you want to do?", commands, no_args) the_command = response[0] # now deal with the command if the_command == 'go': go_where = response[1].lower() if go_where == 'south': next_room = 4 done_with_room = True elif go_where == 'west': next_room = 6 done_with_room = True else: print('You cannot go:', go_where) elif the_command == 'take': response = utils.scrub_response(response) take_what = response[1] utils.take_item(player_inventory, r5_inventory, take_what) elif the_command == 'drop': drop_what = response[1] utils.drop_item(player_inventory, r5_inventory, drop_what) elif the_command == 'status': utils.player_status(player_inventory) utils.room_status(r5_inventory) elif the_command == 'examine': print(room5_description) elif the_command == 'use': use_what = response[1] if use_what == 'button': player_inventory['special_item2'] = 7 print("The button is pressed") elif the_command == 'help': utils.player_help() else: print("The command:", the_command, "has not been implemented in Room 5") # END of WHILE LOOP return next_room
def run_room(player_inventory): room2_description = ''' . . . 2nd room ... You are in a brightly lit room. The room appears to be an office. There is a desk in the center of the room with a key and a flask on top. Next to the desk lies a unremarkable short sword covered in webs and dust. There is an exit to the NORTH and to the SOUTH.''' print(room2_description) # valid commands for this room commands = ["go", "take", "drop", "use", "examine", "status", "help"] no_args = ["examine", "status", "help"] # nonsense room number, we need to figure out which room they want in the loop next_room = -1 done_with_room = False while not done_with_room: # Examine the response and decide what to do response = utils.ask_command("What do you want to do?", commands, no_args) response = utils.scrub_response(response) the_command = response[0] if the_command == 'go': direction = response[1] # Use your hand drawn map to help you think about what is valid if direction == 'north': next_room = 1 done_with_room = True elif direction == 'south': next_room = 7 done_with_room = True else: # In this room, there is nowhere else to go. print("There is no way to go,", direction) elif the_command == 'take': response = utils.scrub_response(response) take_what = response[1] utils.take_item(player_inventory, r2_inventory, take_what) elif the_command == 'drop': drop_what = response[1] utils.drop_item(player_inventory, r2_inventory, drop_what) elif the_command == 'status': utils.player_status(player_inventory) utils.room_status(r2_inventory) elif the_command == 'examine': print(room2_description) elif the_command == 'help': utils.player_help() else: print("Command not implemented in ROOM 2,", the_command) # end of main while loop return next_room
def run_room(player_inventory): # Let the user know what the room looks like if room_state['pitch_black'] == True: print(room4_dim_description) else: print(room4_lit_description) # valid commands for this room commands = ["go", "take", "drop", "use", "examine", "status", "help"] no_args = ["examine", "status", "help"] # nonsense room number, # In the loop below the user should eventually ask to "go" somewhere. # If they give you a valid direction then set next_room to that value next_room = -1 done_with_room = False while not done_with_room: # Examine the response and decide what to do response = utils.ask_command("What do you want to do?", commands, no_args) the_command = response[0] # now deal with the command if room_state['pitch_black'] == False: if the_command == 'go': go_where = response[1].lower() if go_where == 'south': next_room = 3 done_with_room = True elif go_where == 'north': next_room = 5 done_with_room = True else: print('You cannot go:', go_where) elif the_command == 'take': response = utils.scrub_response(response) take_what = response[1] utils.take_item(player_inventory, r4_inventory, take_what) elif the_command == 'drop': drop_what = response[1] utils.drop_item(player_inventory, r4_inventory, drop_what) elif the_command == 'use': use_what = response[1] if use_what == 'torch': if utils.has_a(player_inventory, 'torch') == True: pitch_black = room_state['pitch_black'] if pitch_black: room_state['pitch_black'] = False print("The room is filled with bright light!") else: print("The room is already lit!") elif use_what == 'sword': if utils.has_a(player_inventory, 'short sword'): print( "You put your short sword into the sheath and it fits perfectly. The chest next to it " "opens and inside you can see a key.") player_inventory['short sword'] = player_inventory[ 'short sword'] - 1 r4_inventory['key'] = r4_inventory['key'] + 1 else: print("You don't possess the correct item") else: print("You need a torch to operate in this room") elif the_command == 'status': utils.player_status(player_inventory) utils.room_status(r4_inventory) elif the_command == 'examine': print(room4_lit_description) elif the_command == 'help': utils.player_help() else: print("The command:", the_command, "has not been implemented in Room 4") else: if the_command == 'use': use_what = response[1] if use_what == 'torch': if utils.has_a(player_inventory, 'torch') == True: pitch_black = room_state['pitch_black'] if pitch_black: room_state['pitch_black'] = False print("The room is filled with bright light!") player_inventory[ 'torch'] = player_inventory['torch'] - 1 print(room4_lit_description) else: print("The room is already lit!") else: print("You need a torch to operate in this room") else: print("You cannot use that") elif the_command == 'examine': print(room4_dim_description) elif the_command == 'status': utils.player_status(player_inventory) elif the_command == 'go': go_where = response[1].lower() if go_where == 'south': next_room = 3 done_with_room = True elif the_command == 'help': utils.player_help() else: print("The command:", the_command, "has not been implemented in Room 4") # END of WHILE LOOP return next_room
def run_room(player_inventory): # Let the user know what the room looks like if room_state['pitch_black']: print(room12_dim_description) else: print(room12_lit_description) # valid commands for this room commands = ["go", "take", "drop", "use", "examine", "status", "help"] no_args = ["examine", "status", "help"] # nonsense room number, # In the loop below the user should eventually ask to "go" somewhere. # If they give you a valid direction then set next_room to that value next_room = -1 done_with_room = False while not done_with_room: # Examine the response and decide what to do response = utils.ask_command("What do you want to do?", commands, no_args) the_command = response[0] # now deal with the command if room_state['pitch_black'] == False: if the_command == 'go': go_where = response[1].lower() if go_where == 'south': next_room = 11 done_with_room = True elif go_where == 'east': is_locked = room_state['door_locked'] if not is_locked: next_room = 13 done_with_room = True else: print("Key required to open locked door.") else: print('You cannot go:', go_where) elif the_command == 'take': response = utils.scrub_response(response) take_what = response[1] utils.take_item(player_inventory, r12_inventory, take_what) elif the_command == 'drop': drop_what = response[1] utils.drop_item(player_inventory, r12_inventory, drop_what) elif the_command == 'use': use_what = response[1] if use_what == 'torch': if utils.has_a(player_inventory, 'torch') == True: pitch_black = room_state['pitch_black'] if pitch_black: room_state['pitch_black'] = False print("The room is filled with bright light!") else: print("The room is already lit!") elif use_what == 'key': if utils.has_a(player_inventory, 'key') == True: door_locked = room_state['door_locked'] if door_locked: room_state['door_locked'] = False print("The door to the EAST is unlocked!") player_inventory[ 'key'] = player_inventory['key'] - 1 else: print("The door was already unlocked!") else: print("You need a key to open this door") else: print("You need a torch to operate in this room") elif the_command == 'status': utils.player_status(player_inventory) utils.room_status(r12_inventory) elif the_command == 'examine': print(room12_lit_description) elif the_command == 'help': utils.player_help() else: print("The command:", the_command, "has not been implemented in Room 4") else: if the_command == 'use': use_what = response[1] if use_what == 'torch': if utils.has_a(player_inventory, 'torch') == True: pitch_black = room_state['pitch_black'] if pitch_black: room_state['pitch_black'] = False print("The room is filled with bright light!") player_inventory[ 'torch'] = player_inventory['torch'] - 1 print(room12_lit_description) else: print("The room is already lit!") else: print("You need a torch to operate in this room") else: print("You cannot use that") elif the_command == 'examine': print(room12_dim_description) elif the_command == 'status': utils.player_status(player_inventory) elif the_command == 'go': go_where = response[1].lower() if go_where == 'south': next_room = 11 done_with_room = True elif the_command == 'help': utils.player_help() else: print("The command:", the_command, "has not been implemented in Room 12") # END of WHILE LOOP return next_room
def run_room(player_inventory): room1_description = ''' . . . Main Room . . . You open your eyes. The room you see is musty and dank. You look around and see a brightly lit doorway to the SOUTH as well as a closed door with a small keyhole To the EAST. Inside this room is nothing to pick up, but you scan and see a rather large button is protruding in the northern wall. ''' print(room1_description) # valid commands for this room commands = ["go", "take", "drop", "use", "examine", "status", "help"] no_args = ["examine", "status", "help"] # nonsense room number, we need to figure out which room they want in the loop next_room = -1 done_with_room = False while not done_with_room: # Examine the response and decide what to do response = utils.ask_command("What do you want to do?", commands, no_args) the_command = response[0] if the_command == 'go': direction = response[1] # Use your hand drawn map to help you think about what is valid if direction == 'south': next_room = 2 done_with_room = True elif direction == 'east': is_locked = room_state['door_locked'] if not is_locked: next_room = 3 done_with_room = True else: print("Key required to open locked door.") else: # In this room, there is nowhere else to go. print("There is no way to go,", direction) elif the_command == 'take': take_what = response[1] utils.take_item(player_inventory, r1_inventory, take_what) elif the_command == 'drop': drop_what = response[1] utils.drop_item(player_inventory, r1_inventory, drop_what) elif the_command == 'use': use_what = response[1] if use_what == 'key': if utils.has_a(player_inventory, 'key') == True: door_locked = room_state['door_locked'] if door_locked: room_state['door_locked'] = False print("The door to the EAST is unlocked!") player_inventory['key'] = player_inventory['key'] - 1 else: print("The door was already unlocked!") else: print("You need a key to open this door") if use_what == 'button': player_inventory['special_item'] = 7 print("The button is pressed") elif the_command == 'examine': print(room1_description) elif the_command == 'status': utils.player_status(player_inventory) utils.room_status(r1_inventory) elif the_command == 'help': utils.player_help() else: print("Command not implemented in ROOM 1,", the_command) # end of while loop return next_room
def run_room(player_inventory): # Let the user know what the room looks like print(room6_description) # valid commands for this room commands = ["go", "take", "drop", "use", "examine", "status", "help"] no_args = ["examine", "status", "help"] # nonsense room number, # In the loop below the user should eventually ask to "go" somewhere. # If they give you a valid direction then set next_room to that value next_room = -1 if utils.has_a(player_inventory, 'special_item'): if utils.has_a(player_inventory, 'special_item2'): if utils.has_a(player_inventory, 'special_item3'): print( "\tA hole has opened up in the western wall and you can see the light of day." "\n\tIt is apparent the end is near.") done_with_room = False while not done_with_room: # Examine the response and decide what to do response = utils.ask_command("What do you want to do?", commands, no_args) the_command = response[0] # now deal with the command if the_command == 'go': go_where = response[1].lower() if go_where == 'east': next_room = 5 done_with_room = True elif go_where == 'west': if utils.has_a(player_inventory, 'special_item'): if utils.has_a(player_inventory, 'special_item2'): if utils.has_a(player_inventory, 'special_item3'): room_state['ending_closed'] = False is_closed = room_state['ending_closed'] if not is_closed: next_room = 14 done_with_room = True else: print( "You cannot fit through this small of an opening." ) else: print( "You cannot fit through this small of an opening." ) else: print( "You cannot fit through this small of an opening.") else: print("You cannot fit through this small of an opening.") else: print('You cannot go:', go_where) elif the_command == 'take': response = utils.scrub_response(response) take_what = response[1] utils.take_item(player_inventory, r6_inventory, take_what) elif the_command == 'drop': drop_what = response[1] utils.drop_item(player_inventory, r6_inventory, drop_what) elif the_command == 'status': utils.player_status(player_inventory) utils.room_status(r6_inventory) elif the_command == 'examine': print(room6_description) elif the_command == 'help': utils.player_help() else: print("Command not implemented in ROOM 6,", the_command) # END of WHILE LOOP return next_room
def run_room(player_inventory): # Let the user know what the room looks like print(room11_description) # valid commands for this room commands = ["go", "take", "drop", "use", "examine", "status", "help"] no_args = ["examine", "status", "help"] # nonsense room number, # In the loop below the user should eventually ask to "go" somewhere. # If they give you a valid direction then set next_room to that value next_room = -1 done_with_room = False while not done_with_room: # Examine the response and decide what to do response = utils.ask_command("What do you want to do?", commands, no_args) the_command = response[0] # now deal with the command if the_command == 'go': go_where = response[1].lower() if go_where == 'west': next_room = 9 done_with_room = True elif go_where == 'north': next_room = 12 done_with_room = True else: print('You cannot go:', go_where) elif the_command == 'take': response = utils.scrub_response(response) take_what = response[1] utils.take_item(player_inventory, r11_inventory, take_what) elif the_command == 'drop': drop_what = response[1] utils.drop_item(player_inventory, r11_inventory, drop_what) elif the_command == 'use': use_what = response[1] if use_what == 'flask': if utils.has_a(player_inventory, 'flask'): print( "You scoop the milk up into the flask and put it into your inventory" ) player_inventory['flask'] = player_inventory['flask'] - 1 player_inventory['milk'] = player_inventory['milk'] + 1 else: print("You cannot use imaginary objects") else: print("Not useful in this room") elif the_command == 'status': utils.player_status(player_inventory) utils.room_status(r11_inventory) elif the_command == 'examine': print(room11_description) elif the_command == 'help': utils.player_help() else: print("The command:", the_command, "has not been implemented in Room 11") # END of WHILE LOOP return next_room
def run_room(player_inventory): # Let the user know what the room looks like if room_state['empty'] == False: print(room10_initial_description) else: print(room10_finished_description) # valid commands for this room commands = ["go", "take", "drop", "use", "examine", "status", "help"] no_args = ["examine", "status", "help"] # nonsense room number, # In the loop below the user should eventually ask to "go" somewhere. # If they give you a valid direction then set next_room to that value next_room = -1 done_with_room = False while not done_with_room: # Examine the response and decide what to do response = utils.ask_command("What do you want to do?", commands, no_args) the_command = response[0] # now deal with the command if the_command == 'go': go_where = response[1].lower() if go_where == 'north': if utils.has_a(r10_inventory, 'cake'): if utils.has_a(r10_inventory, 'milk'): print( '"Wait adventurer" says the old man in a panicked fashion "Do not forgot your reward."' '\nHe reaches into this robes and pulls out a key, but soon drops it to finish his tasty' '\ntreat. "It is yours" He proceeds "I have no need for it anymore"' ) r10_inventory['key'] = r10_inventory['key'] + 1 r10_inventory['cake'] = r10_inventory['cake'] - 1 r10_inventory['milk'] = r10_inventory['milk'] - 1 empty = room_state['empty'] if empty == False: room_state['empty'] = True else: next_room = 9 done_with_room = True else: next_room = 9 done_with_room = True else: print('You cannot go:', go_where) elif the_command == 'take': response = utils.scrub_response(response) take_what = response[1] utils.take_item(player_inventory, r10_inventory, take_what) elif the_command == 'drop': response = utils.scrub_response(response) drop_what = response[1] utils.drop_item(player_inventory, r10_inventory, drop_what) if drop_what == 'cake': print('"Thank you kind person" the old man says') if drop_what == 'milk': print('"Thank you kind person" the old man says') elif the_command == 'status': utils.player_status(player_inventory) utils.room_status(r10_inventory) elif the_command == 'examine': print(room10_initial_description) elif the_command == 'help': utils.player_help() else: print("The command:", the_command, "has not been implemented in Room 10") # END of WHILE LOOP return next_room