As many other askers on this site seem to be doing, I am using Learn Python the Hard Way to, well, learn Python.
I am on Lesson 36, in which we create our own BBS-style text game based on the one he led us through in Lesson 35.
http://learnpythonthehardway.org/book/ex36.html
http://learnpythonthehardway.org/book/ex35.html
I wanted to up the "difficulty" of the game, so I made the maze a little more complex. Instead of one entrance in and one out of each room, some rooms have multiple doors. Some of those doors lead to nothing, but some rooms can be entered from multiple rooms within the map.
So, in the monster_room, the player can enter via the monkey_room or the empty_room. The problem is, the monster_room runs the same code, no matter where the player enters from. Since I built the empty_room first, the door choices and results are based on that room.
Here's the monster_room code:
def monster_room():
print "You have stumbled into a dark room with a giant, but friendly, monster."
print "There are four doors:"
print "One straight ahead, one to your right, one to your left, and the one you just entered through."
print "Which door would you like to choose?"
door = raw_input("> ")
if "left" in door:
dead("The door magically recedes into the wall behind you and you find yourself forever trapped in a black room with no doors, no windows, and no hope of escape.")
elif "right" in door:
monkey_room()
elif "straight" in door:
dead("You step into the abyss and fall through nothingness to your certain death.")
else:
print "You found a magical shortcut to the Treasure Room!"
treasure_room()
Okay, so pretty simple, right? But, if someone enters from the monkey room, the positions of the doors is different. Left would lead to the empty room, right to the abyss, straight to trapped forever, and back the way you came still a magical shortcut.
I know I could just create a monster_room_2 or something that would only be entered from the monkey_room and have all the doors in the "right place", but I thought there might be a way to have the game give options based on the function that sent them there. Does that make sense?
Any help would be greatly appreciated.
came_fromparameter for each room, indicating which room you were just in. Then you haveif came_from == "monkey_room":, followed by your if/elif/else blocks, then anelif came_from == "empty room":, followed by another if/elif/else block. It could get quite tedious to write -- requiring up to 16 conditionals if the room can be entered from all four directions -- but it's not particularly difficult.