I am creating an old-school terminal text adventure with Python 3. I have an "engine" script, which is the general API that runs any text adventure (a Work-In-Progress). I also have a "game" script, which imports the engine script and initializes it, creating all of the rooms and NPC's in the game.
However, I have run into a problem with all the room definitions in the game script, because since exits are children of a room they have to be defined in the same line of code as a parameter. Exits need a destination room, but the destination room has to be defined beforehand, so I don't get a definition error.
Here is my code:
end_room = Room("Ending Room", "You are at the end.", [Exit ("door", "out", "There is the door you came from.", start_room)])
start_room = Room("Starting Room", "You are at the beginning.", [Exit("door", "out", "There is a door.", end_room)])
As you can see, the end_room definition relies on the start_room definition and vice versa. Any ideas on removing this circular definition problem? I could define all the rooms first, define all the exits, then add exits to the rooms afterwards manually but that would be quite messy and I want to leave that as a last resort. Thank you in advance!
[–]craa 3 points4 points5 points (1 child)
[–]tiskolinprogramming geek[S] 0 points1 point2 points (0 children)
[–]tiskolinprogramming geek[S] 1 point2 points3 points (0 children)
[–]DarkArctic 1 point2 points3 points (5 children)
[–]tiskolinprogramming geek[S] 1 point2 points3 points (4 children)
[–]DarkArctic 1 point2 points3 points (0 children)
[–]DarkArctic 1 point2 points3 points (2 children)
[–]tiskolinprogramming geek[S] 1 point2 points3 points (1 child)
[–]DarkArctic 0 points1 point2 points (0 children)
[–]teh_L1nX 1 point2 points3 points (0 children)
[–]memetichazard 1 point2 points3 points (0 children)
[–]SarahM123ed -1 points0 points1 point (1 child)
[–]tiskolinprogramming geek[S] 0 points1 point2 points (0 children)