示例#1
0
def run_room(player_inventory):
    # Let the user know what the room looks like
    utils.print_description(room9_description)


    # valid commands for this room
    commands = ["go", "take", "drop", "use", "status"]
    no_args = ["status"]

    # 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)
        response = utils.scrub_response(response)
        the_command = response[0]

        # now deal with the command
        if the_command == 'go':
            go_where = response[1].lower()
            if go_where == 'south':
                is_locked = room8_state['door locked']
                if not is_locked:
                    next_room = 8
                    done_with_room = True
                else:
                    print('The door to Room 8 is locked.')
            else:
                print('You cannot go:', go_where)
        elif the_command == 'take':
            take_what = response[1]
            utils.take_item(player_inventory, room9_inventory, take_what)
        elif the_command == 'drop':
            drop_what = response[1]
            utils.drop_item(player_inventory, room9_inventory, drop_what)
        elif the_command == 'status':
            utils.player_status(player_inventory)
            utils.room_status(room9_inventory)
        elif the_command == 'use':
            use_what = response[1]
            if use_what in player_inventory:
                if use_what == 'key':
                    direction = utils.prompt_question('Which door would you like to use the key on?', ['south'])
                    if direction.lower() == 'south':
                        print('The door was already unlocked')

                else:
                    print('You have no way to use:', use_what)
            else:
                print("You don't have:", use_what)
        else:
            print('The command:', the_command, 'has not been implemented in room 9.')


            # END of WHILE LOOP
    return next_room
示例#2
0
def run_room(player_inventory):
    utils.print_description(description)
    # valid commands for this room
    commands = ["go", "take", "drop", "use", 'status']
    no_args = ["status"]

    # 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':
                is_locked = room4_state['door locked']
                if not is_locked:
                    next_room = 4
                    done_with_room = True
                elif is_locked:
                    print("The door to room 4 is locked.")
            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, room2_inventory, take_what)

        elif the_command == 'drop':
            drop_what = response[1]
            utils.drop_item(player_inventory, room2_inventory, drop_what)

        elif the_command == 'status':
            utils.player_status(player_inventory)
            utils.room_status(room2_inventory)

        elif the_command == 'use':
            use_what = response[1]
            if use_what in player_inventory:
                object = use_what.split()
                if object[1] == 'key':
                    direction = utils.prompt_question(
                        'Which door would you like to use the key on?',
                        ['north', 'south'])
                    if direction.lower() == 'north':
                        print('The door was already unlocked')
                    elif direction.lower() == 'south':
                        door_locked = room4_state['door locked']
                        if door_locked:
                            if object[0] == 'brass':
                                room4_state['door locked'] = False
                                current_count = player_inventory['brass key']
                                player_inventory[
                                    'brass key'] = current_count - 1
                                print('The door to the SOUTH is now unlocked.')
                            else:
                                print('A', use_what, 'is unable to unlock the',
                                      direction, 'door.')
                        else:
                            print('The door was already unlocked.')
                else:
                    print('You have no way to use:', use_what)
            else:
                print("You don't have:", use_what)
        elif the_command == 'examine':
            examine_what = response[1]

        else:
            print("Command not implemented in ROOM 2,", the_command)

    # end of main while loop
    return next_room
示例#3
0
def run_room(player_inventory):
    utils.print_description(room3_description)

    # valid commands for this room
    commands = ["go", "take", "drop", "use", 'status']
    no_args = ["status"]

    # 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)
        response = utils.scrub_response(response)
        the_command = response[0]

        # now deal with the command
        if the_command == 'go':
            go_where = response[1].lower()
            if go_where == 'west':
                is_locked = room1_state['door locked']
                if not is_locked:
                    next_room = 1
                    done_with_room = True
                else:
                    print('The door to Room 1 is locked.')
            elif go_where == 'north':
                print(
                    'Walking up to the door you see that the door says exit. \n You have finally made it. \n Type go EXIT to escape.'
                )
            elif go_where == 'exit':
                next_room = 0
                done_with_room = True
            else:
                print('You cannot go:', go_where)

        elif the_command == 'take':
            take_what = response[1]
            utils.take_item(player_inventory, room3_inventory, take_what)

        elif the_command == 'drop':
            drop_what = response[1]
            utils.drop_item(player_inventory, room3_inventory, drop_what)

        elif the_command == 'status':
            utils.player_status(player_inventory)
            utils.room_status(room3_inventory)

        elif the_command == 'use':
            use_what = response[1]
            if use_what in player_inventory:
                if use_what == 'key':
                    direction = utils.prompt_question(
                        'Which door would you like to use the key on?',
                        ['west', 'north'])
                    if direction.lower() == 'west':
                        door_locked = room1_state['door locked']
                        if door_locked:
                            room1_state['door locked'] = False
                            current_count = player_inventory['key']
                            player_inventory['key'] = current_count - 1
                            print('The door to the WEST is now unlocked.')
                        else:
                            print('The door was already unlocked')
                    elif direction.lower() == 'north':
                        door_locked = room_end_state['door_locked']
                        if door_locked:
                            if object[0] == 'wood':
                                room_end_state['door locked'] = False
                                current_count = player_inventory['wood key']
                                player_inventory[
                                    'wood key'] = current_count - 1
                                print(
                                    'The EXIT door is now unlocked. Type go EXIT to escape.'
                                )
                            else:
                                print('A', use_what, 'is unable to unlock the',
                                      direction, 'door.')
                else:
                    print('You have no way to use:', use_what)
            else:
                print("You don't have:", use_what)
        else:
            print('The command:', the_command,
                  'has not been implemented in room 3.')

            # END of WHILE LOOP
    return next_room