from sys import exit from random import randint from game_room import * class Hallway(object): """\tYou are in a warehouse with 2 doors. Which one do you try to open? Number 1 or 2? """ def run(self): door = raw_input("> ") if door == "first" or door == "1": next_room = Puzzle_room() return next_room elif door == "second" or door == 2: next_room = death() return next_room else: print "DO NOT COMPUTE!" exit(0) class Puzzle_room(object): """\tPuzzles, puzzles, puzzles, oh the lovely puzzles. I hope you like them. Here is one: Which of the three boxes in front of you has the key to the next room? And which one has a poisonous snake in it and which one has a grenade in it? Choose wisely: """ def run(self): box = raw_input("Box #: ") if box == "1" or box == "one": print "\tYou chose the right box! Congratz!" print "\tGo explore some more!" next_room = Empty_room() return next_room elif box == "2" or box == "two": print "\tOh nooo, the grenades splint is removed..." print "\tand you got blow into pieces. That is sad!" print "\tGame over!" next_room = death() return next_room elif box == "3" or box == "three": print "\tYaaay, the snake is sleeping and you try to open another box" print "\tAs soon as you move the snake wakes up and screams:" print "\tHello, muthafucka! And then he bites you. After which you" print "\ttwist and turn in agonising pain for 10 minutes and die" print "\tNice JOB!" next_room = death() return next_room else: print "\tDo not COMPUTE!" next_room = Puzzle_room() return next_room class Monster_room(object): """\tYou have entered a dark room. In the center of the room is a fire. Above the fire is a sign. The sign says "Feed the beast". What do you do? """ def run(self): the_beast = raw_input("I will: ") if "run" in the_beast: print "\tYou chicken! You run around for hours and die of dehydration." next_room = death() return next_room elif "wait" in the_beast: print "\tYou wait for 3 hours and die of boredom" print "\tNice job!" next_room = death() return next_room elif "feed" in the_beast: print "\tYou are brave, young badavan!" print "\tYou take the meat from the feed box and wave it around" print "\tFinally a little chihaua or smt that looks like a rat" print "\tcomes to you. You throw it the meat and it gives you the" print "\tkey to the next room because it is so intelligent, but" print "\tcan not feed itself." next_room = Basement() return next_room else: print "\tDo not COMPUTE!" next_room = Monster_room() return next_room class Basement(object): """\tYou go down the stairs and into the basement. The basement has another door. The door has a keypad. You need to hack the massive 1 digit code. """ def run(self): code = "%d" % (randint(1,5)) guesses = 0 guess = raw_input("[Keypad]: ") while guess != code and guesses < 4: print "Try again:" guesses += 1 guess = raw_input("[Keypad]: ") if guess == code: print "\tYay, good for you. You will not die of boredom." print "\tRight here right now anyway." print "\tYou see a misterious glow from behind another door" print "\tSice you got big cojones you open the door and enter." next_room = Gold_room() return next_room else: print "\tWhether you do not know your numbers or just suck" print "\tYou can not crack the code and die of hunger." next_room = death() return next_room class Gold_room(object): """\tYou enter a room that is made entirely out of gold. You have to go over a suspicious looking bridge in orde to get out of the warehouse. There is some gold on floor. How many bars do you take? """ def run(self): gold = int(raw_input("# of bars: ")) if gold < 10: print "\tCongratz, you win! You got out of the warehouse." exit(0) else: print "\tYou greedy mofo!" print "\tThe bridge collapses beacause you took to much!" print "\tEnjoy beeing dead." next_room = death() return next_room class death(object): """\tYou are dead. """ def run(self): exit(0) class runner(object): def __init__(self, start): self.start = start def play(self): next_room = self.start while True: print "---------------" * 4 print next_room.__doc__ next_room = next_room.run() first_room = Hallway() game = runner(first_room) game.play()
game_room.py , which is just to use another file, contains 1 simple room / class
class Empty_room(object): """\tThe room is totally empty. There is a crayon on the floor. Draw yourself a door to get out of this place. """ def run(self): print "\tThat is one ugly ass door." next_room = Monster_room() return next_room
When I run it, and get to the end of the Empty_room, Which should direct me to Monster_room, I get a name error:
global name Monster_room is not defined
I guess it is probably a simple solution to this problem, but I can not figure it out, since I do import
evrything from game_room.py so it should work, but obviously does not. Can someone help me? Any help is appreciated