[Python] Text based rpg refusing to move past invalid input if statement

Discussão em 'Python' iniciado por Stack, Abril 15, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently learning Python and am stuck while making a text-based game for moving and picking up items to defeat a boss.

    The issue I'm currently stuck on is that my movement function is not changing rooms and is printing the invalid input message I have set up.

    Here's the code I have so far.

    def move(current_room, direction, rooms):
    #Set acceptable inputs
    valid_inputs = ['North', 'South', 'East', 'West', 'Exit', 'Quit']

    #Loop to determine the move is valid
    if direction.strip() not in valid_inputs:
    print("Invalid input.")
    print('-'*15)
    return current_room



    elif direction in rooms[current_room]:
    new_room = rooms[current_room][direction]

    if 'item' in rooms[current_room]:
    print('You see a ', rooms['item'])

    else:
    return new_room

    #Invalid move response
    else:
    print("There's nothing in that direction.")
    print('-' * 15)
    return current_room


    #Player Status
    def show_status():
    print('You are in the {}'.format(current_room))
    print('Inventory: '.format(inventory))
    print('-'*15)
    return show_status

    #Show Rules
    rules()

    #Gameplay Loop
    while True:

    if current_room == 'Ritual Chamber':
    if len(inventory) == 6:
    print('Congratulations! You have defeated the necromancer!\nThe surrounding towns are safe again!')
    break
    else:
    print('Oh no! You\'ve become the necromancer\'s next victim!')
    break

    show_status()
    direction = input('Which direction would you like to explore? ').upper()
    print('-'*15)

    if direction == 'Quit' or direction == 'Exit':
    print('You have quit the game.\nThank you for playing.')
    break

    current_room = move(current_room, direction, rooms)

    Continue reading...

Compartilhe esta Página