Text Adventure: Mentioning the dictionary inside itself

Thank you for explaining to me lambda and broadening my knowledge. I appreciate you very much.

I think 3D array can make the thing unnecessarily complicated and also limiting. You can design your map on paper then you put the places to an (unordered) dict where you can use the names of the places as a key (if they are unique).

Every place can then contain dict of directions you can go, they will refer to the destination places by their unique names.

It is still a kind of the finite-state machine where the places are states (of your position) and directions are the inputs telling which direction the player wants to go.

PLACES = {
    'Bathroom': (
        ...,   # the items, descriptions and other data you need for the place...
        {      # here is the dict of directions you can go and where you will appear after taking the direction
            's': 'Bedroom',
            'u': 'Upstairs',
        }
    ),
    'Bedroom': (
        ...,  # another place content...
    ),
    # etc...
}

The structure you create this way will be:

Sorry, but you might want to read this post. In it I posted an example of my current code, that is quite similar to your suggestion. :slight_smile:

OK, I just wanted to point out that it probably does not make sense to try to arrange the places into a 2D or 3D array. Just leave them unordered in a dict.

1 Like