[Python] Debugging Moving into Room for Text Game [closed]

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

  1. Stack

    Stack Membro Participativo

    This is my first post. I'm working on the famous "Dragon Text Game" project for new programmers of Python. I've gotten most of my base code working, except for some reason, I can't figure out why my code is testing negative for being able to move into a room. I'll include snippets of my code below. They appear in this order.

    I have this (piece of) dictionary for the rooms (it's a Norse-themed game! :3 )...


    realms = {
    'Midgard': {'North': 'Asgard', 'South': 'Muspelheim', 'East': 'Vanaheim', 'West': 'Alfheim'},
    'Asgard': {'North': 'Jotunheim', 'South': 'Midgard', 'East': 'Niflheim'}
    }


    This is a couple of functions I've used to see whether or not the player can move north into a room.


    DIRECTION_NORTH = 'North'

    def can_go_north(current_world):
    return current_world in realms and DIRECTION_NORTH in realms[current_world]


    def go_north(current_world):

    if can_go_north(current_world):
    updated_world = realms[current_world][DIRECTION_NORTH]
    print(f'You are now in the realm of {updated_world}.')
    print(realm_intro[updated_world])
    else:
    updated_world = current_world
    print("You cannot go North from here. Try again.")

    return updated_world


    Lastly, this is in the main body of code where I'm implementing the functions in the game.

    while current_realm != 'Hel':
    print("Enter a command. Enter \"Help\" for list of commands.")
    command = input()
    if command == "Help":
    print('Commands: Get Item, Go North, Go South, Go East, Go West, Help, Inventory.')
    elif command == "Inventory" :
    print(inventory)
    print('You have ',len(inventory),' of seven relics.')
    elif command == "Get Item":
    get_item(current_realm)
    elif command == "Go North" :
    current_realm = go_north(current_realm)
    else :
    print("Invalid command. Enter 'Help' for command list.")

    if current_realm == 'Hel':
    endgame()


    Every time I run the game and attempt to move North from Midgard (starting room) into Asgard, my program blocks me and prints "You cannot go North from here. Try again." I wonder if I mistyped anything in my dictionary syntax-wise, but I've checked over and over again. I've also had help with the AI in PyCharm, but it can't seem to catch my problem.

    Anyone got any ideas? Thanks so much! :D

    Continue reading...

Compartilhe esta Página