Hello! I'm starting to learn python and are doing a "big" assigment for my programming course.
I'm having trouble how to structuralize my code, I have gotten some not that good feedback so I could really use some help.
What am I doing wrong?
This is my code so far.
#31/03-15 For the introduction type effect import sys from time import sleep #31/03-15 The players inventory, at each "checkpoint" the player should be able to check his/hers inventory. inventory =  #31/03-15 The main function print the "menu" of the game, it introduces the player tp the game. def main(): print("Welcome to <spelnamn>") print("Hints:") print("Inventory:") print("Help")#Don't know if I want this function yet. 2/4-15 flag = True while flag: Start = input("Type start to begin: ") if Start == "start": #31/03-15 if the player types "start" the textfile Introduction will be printed out on the scree, with a "type writer" effect. Introduction = open("Introduction.txt","r") for x in Introduction: for letter in x: sys.stdout.write(letter) sys.stdout.flush()#31/03-15 Python's standard out is buffered (meaning that it collects some of the data "written" to standard out before it writes it to the terminal). Calling sys.stdout.flush() forces it to "flush" the buffer, meaning that it will write everything in the buffer to the terminal, even if normally it would wait before doing so. sleep(0.050) flag = False elif Start != "start": #31/03-15 if the player type anything else other than "start" "Follow the instructions" will be printed out and will loop back the player. print("Follow the instructions!") #main() #The player finds a flashlight and batteries in the emergency box, they are both added to the inventory. def emergency_box(inventory): print("A flashlight and some batteries are added to your inventory\n") addToInventory("flashlight") addToInventory("batteries") def addToInventory(item): inventory.append(item) emergency_box(inventory) #31/03-15 class for Room, the objects for Room are the different rooms in the game. class Room: """ Class for room. Objects: name, description """ def __init__ (self,name,description): """ init for objectvariables. parameter name: sting parameter description: string """ self.name = name self.description = description self.exit = dict() #31/3-15 I Should change the choices here do the player types in the way they want to go instead of numbers, that's a bit boring. FIXED 2/4-15 def corridor(self): """ The player enters the room corridor(G1) the player can choose where to go. """ print("You are in room %s and %s\n" % (self.name, self.description)) print("From where you are you see three doors, their signs read\n %s\n %s\n %s" % (G1.exit["Door to F1"].name, G1.exit["Door to H1"].name, G1.exit["Door to D1"].name)) print("Where do you go?") flag = True while flag: try: choice = input(">").capitalize() if choice == "Dumpingroom": print("You open the door and shine your flashlight inside, you must be in some sort of %s and inside %s" % (D1.name, D1.description))#2/4-15 change this description elif choice == "Future lab": room = G1.exit["Door to H1"] print("You stop at the door and shine you flashlight on a sign that says %s, %s" %(room.name, room.description)) H1.laboratory()#the player enters "future lab" flag = False elif choice == "untitled": print("%s" % (F1.description),"You decide to to back") elif choice == "Check inventory": print(inventory) else: raise RuntimeError except: print("There is no places called that.") #31/3-15 the method loboratory gets you inside room H1, once in H1 you will be able to to A1,B1 and C1 byt typing in their names. #31/3-15 Much more fin if the player has to typr in the room name, try and fix some Upper/Lower thingy function. #31/3-15 the while loop will let you type again if you do it wrong the first time. #2/4-15 Changed the choice stairwell and server room to function different if you have the key or not. def laboratory(self): """ The players enter the room "future lab"(H1) The player have some choices to where he/she can go. """ print("Even though tha room is lage you can make out three doors, their signs read,\n %s \n %s \n %s" % (self.exit["Door to A1"].name, self.exit["Door to B1"].name, self.exit["Door to C1"].name)) print("Where would you like to go?") flag = True while flag: try: choice = input("> ").capitalize() if choice == "Storage": print("%s" % (self.exit["Door to A1"].description)) elif choice == "Server room": if "key" in inventory: print("You have already checked this room") else: print("%s" %(self.exit["Door to B1"].description)) B1.serverroom_key()#The room where the key to the stairwell lays. elif choice == "Stairwell": if "key" in inventory: print("As you remember the door is locked, but you use the key you found in the serverroom to open it.") B2.level_2() flag = False else: print("%s" % (self.exit["Door to C1"].description)) print("You should check the other rooms for a key") else: raise RuntimeError except: print("There is no room with that name, where are you trying to go?") #2/4-15 Event in serverroom, key to C1 def serverroom_key(self): """ Event in the room "serverroom" player finds a key that leads to the stairwell(C1) """ print("You look around the room, maybe there is something in here you can use. You check all the lockers, in one of them you find a key.") flag = True while flag: pick_up = input("Do you want to pick up the key, yes or no? \n >") if pick_up == "yes": print("You pick up the key and put it in your inventory, you wonder where it leads and decide to out and check the other rooms.") addToInventory("key") #print(inventory) flag = False elif pick_up == "no": print("You leave the key in the locker and leave the room") flag = False elif pick_up != "yes" or pick_up != "no": print("You either decide to pick it up or not..") #2-4/15 Leve 2! def level_2(self): """ The player enters level 2 The player have some choice to where he/she can go """ print("You walk up and flight of stair and step inside the door %s you end up in an %s" % (self.name, self.description)) #31/3-15 the rooms on level 1 D1 = Room("Dumpingroom", "A room with stone walls, inside there are decomposing bodies and a small lightbuld hanging from the ceiling") G1 = Room("Corridor", " the room you are in looks like some sort of corridor, the walls are of stone and you are standing next to an emergency box. You shine your flashlight around the room and see cables and light bulbs haning from the ceiling") F1 = Room("untitled", "You arrive at a door, but you cannot push it open, something is in the way. You peek inside but inside shows nothing but darkness") H1 = Room("Future lab", "You step inside a large room, most of it are still rock walls with building material and machines scattered around the room. Boxes with different symbols on them, worker's clothes and other things") B1 = Room("Server room", "You enter the room and what you can see is line after line of large black boxes, lockers with worker's cloths") A1 = Room("Storage", "You step up to the door and shine you flashlight through the small glas pane, inside you see a small gas can and a generator, you try to open the door, bit it's locked") C1 = Room("Stairwell", "You try to open the door but it seems to be locked. Maybe you can open it with a key?.") #31/3-15 the rooms on level 2 A2 = Room("Laboratory", "The room is locked, insaide is a large room with weird machines and 'densit' chair") B2 = Room("Level 2", "ordinary corridor, there are doors everywhere") C2 = Room("Stariwell", "Another stairwell") D2 = Room("Generator room", "The door is dark, you shine your flashlight around the room and see a generator and a gas can next to it.") E2 = Room("Control room", "A small room with computer and screens, you move to the screen/radio where you can head noises") F2 = Room("The Eye room", "don't have a full description here yet.") G2 = Room("","") H2 = Room("","") I2 = Room("","") #31/3-15 Where do all the rooms lead. G1.exit["Door to H1"] = H1 G1.exit["Door to F1"] = F1 G1.exit["Door to D1"] = D1 D1.exit["Door to G1"] = G1 F1.exit["Door to G1"] = G1 H1.exit["Door to G1"] = G1 H1.exit["Door to A1"] = A1 H1.exit["Door to B1"] = B1 H1.exit["Door to C1"] = C1 #C1.exit["Door to B2"] = B2 #G1.corridor() #H1.laboratory()