##This game is special - don't think of it as scoring 90 points ##like metadunnet[3].py! This is the odd one out in everything ##made before it. It's a game called `Family Memory'. try: import winsound except Exception, e: print "WinsoundError: %s" % e h = 2.0**(1.0/12.0) properties = {"prefix": "fm_", "relation": "heartfelt_nightsong"} fm_hole = False fm_on = False fm_bridge_built = False fm_jar_gotten = False fm_dead = False fm_quitted = False fm_jar_objs = 0 fm_current_section = 0 fm_ignore = ["the", "to", "at", "this", "that"] fm_visited = [] fm_section_descr = [ [ """You are in what appears to be your cottage. Near a corner is a television, and near one of the walls is a sofa, which serves as to being your bed. To the west you see a gate which reads 'THE BEST FAMILY REUNIONS'. To the south you see a door. The door is closed and locked. To the north in the distance you can see your backyard.""", "Your house" #0 ], [ """You are in your backyard. There are a lot of plants around you, and your cottage is to the south. A fierce view appears to the northeast, and to the north down a ramp you see a subway station. A trail of leaves go out of sight.""", "Your backyard" ], [ """The leaves continue off to the southeast. You can also go back southwest.""", "SE/SW Junction" ], [ """You are standing on a road which continues to the southeast. You can also go back northwest, and there is a rusty gate off to the northeast.""", "SE/NW road" ], [ """You are standing in front of a medium-sized pothole. A chain of steps go down the pothole from here, and you can also go back northwest.""", "Pothole front" ], [ """You have gone halfway down the pothole. The leaves continue down from here.""", "Middle of pothole" #5 ], [ """You have reached the bottom of the pothole. You notice the leaves somewhat stuck to the stone due to cold weather conditions.""", "Bottom of pothole." ], [ """You are standing at the south side of a subway station, where a man is standing. A ramp going up leads to the south.""", "Subway station south" ], [ """You are at the north side of the subway station. A path continues to the north. You notice the leaves continuing as you walk.""", "Subway station north" ], [ """You are in a meadow. Paths go off to the north and northwest. A subway station is seen to the south.""", "Meadow fork" ], [ """You are on a junction of north and southeast passages.""", "N/SE Junction" #10 ], [ """You are on a hill. There are paths to the north, south, and east.""", "N/S/E Hill" ], [ """You are at the east end of a passageway. The are leaves leading to a tunnel, but you cannot see where they are going.""", "E end of passageway" ], [ """You are at a fork. There are passages to the west and north, and the meadow is to the south.""", "T-shaped fork" ], [ """You are in what looks like the ruins of Death Valley. A path leads off to the east.""", "Ruins" ], [ """This is a dead end. You can also go back south.""", "Northern passage" #15 ], [ """You have reached a junction of passages that go east and south.""", "E/S corner" ], [ """You are standing on a thick stone ground. The path continues east and west.""", "Thick ground" ], [ """The stone on the ground is slightly thinner. The path continues east and west.""", "Thin ground" ], [ """You are standing on a thick stone ground. The path goes west. A door is coming from the south.""", "S/W thick ground" ], [ """You are standing in front of a container store. The supply of containers make you interested. The stone ground is to the north.""", "Container store front" #20 ], [ """There are lots of containers stacked on the counters. Your family is here.""", "Container store" ], [ """You are at the south end of a tunnel which continues to the north. There are lots of lights flashing all around you.""", "Southern tunnel" ], [ """You are in a passage of a tunnel which continues to the north and south.""", "Tunnel N/S passage" ], [ """You are at the north end of the tunnel. There is a path to the west.""", "Northern tunnel" ], [ """You are on a corner where tracks go off to the north and east.""", "N/E tunnel corner" #25 ], [ """You are on a corner where tracks go off to the east and south.""", "E/S tunnel corner" ], [ """There is a cellar door on the ground. A path goes off to the west.""", "Cellar door" ], [ """It's dark. You are likely to be eaten by a grue. The path continues south.""", "Darkness" ], [ """It's dark. A terrible stench surrounds you.""", "Darkness" ], [ """The leaves continue near an airvent up a ramp to the south.""", "Ramp" #30 ], [ """This is a path from the cellar door which continues north and south.""", "Cellar path" ], [ """You are at the corner of two passages, one to the north, and one to the southwest. There are strange sounds around you.""", "NE end of NE/SW passageway" ], [ """You are 3/4 of the way to the northeast end of the passageway.""", "3/4 NE" ], [ """You are in the middle of a long northeast-southwest passageway.""", "Long NE/SW passageway" ], [ """You are 3/4 of the way to the southwest end of the passageway. The path is getting steeper here.""", "3/4 SW" #35 ], [ """You are at the southwest end of the passageway. There is a door to the south.""", "SW end of NE/SW passageway" ], [ """This is your field. There are 5 gravestones on the ground here. A cellar passage appears to the north, and there is a gate to the east.""", "Your field" ], [ """You are in front of your cottage, where your family is standing. Your cottage is to the north, and a path goes to the south.""", "Cottage front" ], [ """The leaves are all piled up on the ground here. It looks as if they were just being blown. A path goes north.""", "Leaf pile-up" ] ] ##Make the section dictionary sect = {} for i in xrange(0, 40): if i == 28: sect["grue-darkness"] = i elif i == 29: sect["light-darkness"] = i else: name = fm_section_descr[i][1].lower() if name[-1] == ".": name = name[0:-1] for letter in xrange(0, len(name)): if not name[letter] in "abcdefghijklmnopqrstuvwxyz0123456789": #Slash, space or something else name = name[0:letter] + "-" + name[letter+1:len(name)] sect[name] = i #The map. dirs = { "north": 0, "south": 1, "east": 2, "west": 3, "n": 0, "s": 1, "e": 2, "w": 3, "northeast": 4, "northwest": 5, "southeast": 6, "southwest": 7, "ne": 4, "nw": 5, "se": 6, "sw": 7, "up": 8, "down": 9, "u": 8, "d": 9, "in": 10, "out": 11, "enter": 10, "exit": 11 } fm_map = [ # nort sout east west ne nw se sw up down in out [1, 127, -1, 127, -1, -1, -1, -1, -1, -1, -1, 1 ], #0 [7, 0, -1, -1, 2, -1, -1, -1, -1, -1, 0, -1 ], #1 [-1, -1, -1, -1, -1, -1, 3, 1, -1, -1, -1, -1 ], #2 [-1, -1, -1, -1, 127, 2, 4, -1, -1, -1, -1, -1 ], #3 [-1, -1, -1, -1, -1, 3, -1, -1, -1, 5, -1, -1 ], #4 [-1, -1, -1, -1, -1, -1, -1, -1, 4, 6, -1, -1 ], #5 [-1, -1, -1, -1, -1, -1, -1, -1, 5, -1, -1, -1 ], #6 [127, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #7 [9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #8 [16, 8, -1, -1, -1, 10, -1, -1, -1, -1, -1, -1 ], #9 [11, -1, -1, -1, -1, -1, 9, -1, -1, -1, -1, -1 ], #10 [13, 10, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #11 [-1, -1, -1, 11, -1, -1, -1, -1, -1, -1, -1, -1 ], #12 [15, 11, -1, 14, -1, -1, -1, -1, -1, -1, -1, -1 ], #13 [-1, -1, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #14 [-1, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #15 [-1, 9, 17, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #16 [-1, -1, 18, 16, -1, -1, -1, -1, -1, -1, -1, -1 ], #17 [-1, -1, 19, 17, -1, -1, -1, -1, -1, -1, -1, -1 ], #18 [-1, 20, -1, 18, -1, -1, -1, -1, -1, -1, -1, -1 ], #19 [19, -1, -1, -1, -1, -1, -1, -1, -1, -1, 21, -1 ], #20 [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 20 ], #21 [23, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #22 [24, 22, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #23 [-1, 23, -1, 25, -1, -1, -1, -1, -1, -1, -1, -1 ], #24 [26, -1, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #25 [-1, 25, 27, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #26 [-1, -1, -1, 26, -1, -1, -1, -1, -1, 127, 127, -1 ], #27 [-1, 127, -1, -1, -1, -1, -1, -1, 27, -1, -1, 27 ], #28 [-1, 30, -1, -1, -1, -1, -1, -1, 27, -1, -1, 27 ], #29 [127, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #30 [30, 32, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], #31 [31, -1, -1, -1, -1, -1, -1, 33, -1, -1, -1, -1 ], #32 [-1, -1, -1, -1, 32, -1, -1, 34, -1, -1, -1, -1 ], #33 [-1, -1, -1, -1, 33, -1, -1, 35, -1, -1, -1, -1 ], #34 [-1, -1, -1, -1, 34, -1, -1, 36, -1, -1, -1, -1 ], #35 [-1, 37, -1, -1, 35, -1, -1, -1, -1, -1, -1, -1 ], #36 [36, -1, 0, -1, -1, -1, -1, -1, -1, -1, 0, -1 ], #37 [0, 39, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1 ], #38 [38, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ] #39 # nort sout east west ne nw se sw up down in out ] #How all objects are referenced. obj = { "cardboard": 0, "box": 0, "dinner": 1, "food": 1, "noodles": 1, "mustard": 2, "gas": 2, "canister": 2, "bridge": 3, "part": 3, "rake": 4, "nitric": 5, "acid": 5, "glycerine": 6, "flashlight": 7, "light": 7, "torch": 7, "jar": 8, "glass": 8, "key": 9, "leaf": -1, "leaves": -1, "cellar": -2, "door": -2, "gravestones": -3, "stones": -3, "grave": -3 } fm_reg_objs = [ ["There is a cardboard box here.", "A cardboard box"], ["There is a plate of noodles here.", "Your dinner"], ["There is a canister of mustard gas here.", "A canister of mustard gas"], ["There is a part of a bridge here.", "A bridge part"], ["There is a rake here.", "A rake"], ["There is a packet of nitric acid here.", "A packet of nitric acid"], ["There is a packet of glycerine here.", "A packet of glycerine"], ["There is a flashlight here.", "A flashlight"], ["There is a glass jar here.", "A glass jar"], ["There is a shiny brass key here.", "A brass key"] ] fm_reg_obj_descr = [ "It is just a plain cardboard box.", "It doesn't smell very good.", "The label says IVC ANIMAL KILLERS INC. on the canister.", "It finishes a bridge for walking over the subway track. You can't just jump!", "A rake from leaf sales in Nevada.", "The acid is strapped in a packet.", "That's slippery glycerine.", None, #Special case! "It is just a plain glass jar.", "You sight a shape of Texas when examining the key." ] fm_perm_obj_descr = [ None, "They are LOTS of leaves that continue out of sight.", "It looks like it's less than 45 degrees from the ground.", """The gravestones read: -Fall of the leaves -Any idea where the leaves start and stopp? -Why are they there? -Where did they come from?""" ] fm_inventory = [] fm_items = [ [obj["box"], obj["noodles"]], #0 [obj["leaves"]], #1 [obj["leaves"]], #2 [obj["leaves"]], #3 [obj["leaves"]], #4 [obj["leaves"]], #5 [obj["gas"], obj["leaves"]], #6 [], #7 [obj["leaves"]], #8 [], #9 [obj["glycerine"]], #10 [], #11 [obj["flashlight"], obj["leaves"]], #12 [], #13 [obj["rake"]], #14 [obj["nitric"]], #15 [], #16 [], #17 [], #18 [], #19 [], #20 [], #21 [], #22 [], #23 [], #24 [], #25 [], #26 [obj["cellar"]], #27 [], #28 [], #29 [obj["leaves"]], #30 [], #31 [], #32 [], #33 [], #34 [], #35 [], #36 [obj["gravestones"], obj["key"]], #37 [], #38 [obj["leaves"]] #39 ] ##Case where I have to report that the unability is serious. def fm_explainShort(): if fm_dead: print "You are dead. All is black. Restart the game by typing 'restart'" else: print fm_section_descr[fm_current_section][1] fm_special_sections() for i in fm_items[fm_current_section]: if i >= 0: print fm_reg_objs[i][0] def fm_explainLong(): if fm_dead: print "You are dead. All is black. Restart the game by typing 'restart'" else: print fm_section_descr[fm_current_section][1] print fm_section_descr[fm_current_section][0] #Describe. fm_special_sections() for i in fm_items[fm_current_section]: if i >= 0: print fm_reg_objs[i][0] def fm_explainIfNew(): if fm_dead: print "You are dead. All is black. Restart the game by typing 'restart'" else: if not fm_current_section in fm_visited: fm_explainLong() fm_visited.append(fm_current_section) else: fm_explainShort() def fm_inven(args): for i in fm_inventory: print "You are carrying %s." % fm_reg_objs[i][1].lower() def fm_serious(args): print "You can't do such a thing. Seriously." def fm_quit(args): global fm_quitted fm_showSign() try: for note in [(0, 2), (12, 4), 10, 7, 10, 7, 5, 3, 5, 3, 5, 7, 5, 3, 0, -2, 0, 3, 0, -2, (0, 8)]: if isinstance(note, tuple): pitch = note[0] ms = note[1] * 250 else: pitch = note ms = 250 winsound.Beep(int(440*h**pitch), ms) except Exception, e: print "WinsoundError: %s" % e print "Goodbye!" fm_quitted = True def fm_restart(args): global fm_hole, fm_on, fm_bridge_built, fm_jar_gotten, fm_dead, fm_quitted, fm_jar_objs, fm_current_section, \ fm_visited, fm_inventory, fm_items fm_hole = False fm_on = False fm_bridge_built = False fm_jar_gotten = False fm_dead = False fm_quitted = False fm_jar_objs = 0 if fm_current_section == 0: fm_explainLong() fm_current_section = 0 fm_visited = [] fm_inventory = [] fm_items = [ [obj["box"], obj["noodles"]], #0 [obj["leaves"]], #1 [obj["leaves"]], #2 [obj["leaves"]], #3 [obj["leaves"]], #4 [obj["leaves"]], #5 [obj["gas"], obj["leaves"]], #6 [], #7 [obj["leaves"]], #8 [], #9 [obj["glycerine"]], #10 [], #11 [obj["flashlight"], obj["leaves"]], #12 [], #13 [obj["rake"]], #14 [obj["nitric"]], #15 [], #16 [], #17 [], #18 [], #19 [], #20 [], #21 [], #22 [], #23 [], #24 [], #25 [], #26 [obj["cellar"]], #27 [], #28 [], #29 [obj["leaves"]], #30 [], #31 [], #32 [], #33 [], #34 [], #35 [], #36 [obj["gravestones"], obj["key"]], #37 [], #38 [obj["leaves"]] #39 ] def fm_special_sections(): ##Any special properties about a section. global fm_current_section if fm_current_section == sect["subway-station-south"]: if not fm_bridge_built: print "There is a half of a bridge on the other side of the track." else: print "There is a tall bridge which goes right over the track." elif fm_current_section == sect["thin-ground"]: if fm_hole: print "You fall into a hole in the ground." fm_current_section = sect["southern-tunnel"] fm_explainIfNew() def fm_special_move(direction): ##Note that there are several of these. global fm_current_section, fm_dead, fm_inventory if fm_current_section == sect["your-house"]: if direction == 1: if not obj["key"] in fm_inventory: print "You have no key that can open this door." else: fm_current_section = sect["cottage-front"] else: print "The gate is not opening." elif fm_current_section == sect["se-nw-road"]: if not obj["gas"] in fm_inventory: print \ """As you open up the rusty gate, you hear the loud sound as a tiger leans forward and bites you with its sharp teeth. Before the world blackens before your eyes, you see a bridge part lying before you. You are dead. Type 'restart' to restart playing. I hope this is a lesson for you to save often.""" fm_dead = True fm_items[fm_current_section] = [] else: print \ """As you open up the rusty gate, you hear the sound of a tiger panting in great displeasure. You then begin coughing, dropping the canister of mustard gas on the ground. The tiger falls to the ground killed. You pick up the bridge part and leave before it's too late. You quickly return to the path.""" fm_inventory.remove(obj["gas"]) fm_inventory.append(obj["part"]) elif fm_current_section == sect["subway-station-south"]: if not fm_bridge_built: print \ """You fall into the train track. You look up and notice that everything is blocked by walls. Then you notice a train begin to move towards you. Before you could escape, the train speeds over you in half a second. You are dead. Type 'restart' to restart playing. I hope this is a lesson for you to save often.""" fm_dead = True fm_items[fm_current_section] = [] else: fm_current_section = sect["subway-station-north"] elif fm_current_section == sect["cellar-door"]: if not (fm_on and obj["flashlight"] in fm_inventory): fm_current_section = sect["grue-darkness"] else: fm_current_section = sect["light-darkness"] elif fm_current_section == sect["grue-darkness"]: print \ """You walk towards a grue which swallows you into little chunks of flesh. You are dead. Type 'restart' to restart playing.""" fm_dead = True fm_items[fm_current_section] = [] elif fm_current_section == sect["ramp"]: if not (fm_on and obj["flashlight"] in fm_inventory): fm_current_section = sect["grue-darkness"] else: fm_current_section = sect["light-darkness"] def fm_move(args): ##Use the map to figure out where we are going. ##If a request yields -1, you cannot go there. ##If it yields 127 then the move is special (in fm_special_move). global fm_current_section if args == []: print "Go where?" else: if not args[0] in dirs: print "Go where?" else: if fm_dead: print "You cannot go there." else: direct = dirs[args[0]] newroom = fm_map[fm_current_section][direct] if newroom == -1: print "You cannot go there." elif newroom == 127: fm_special_move(direct) else: fm_current_section = newroom for i in ["north", "south", "east", "west", "northeast", "northwest", "southeast", "southwest", "up", "down", "in", "out"]: execution = "def fm_" execution = execution + i execution = execution + "(args):\n fm_move(['" execution = execution + i execution = execution + "'])\n" exec execution def fm_rake(args): global fm_dead if args == []: print "Rake what?" else: if not args[0] in obj: print "There is no %s here." % args[0] else: objnum = obj[args[0]] if not objnum in fm_items[fm_current_section]: print "There is no %s here." % args[0] else: if objnum == obj["leaves"]: if not obj["rake"] in fm_inventory: print "You have nothing you can use to rake the leaves!" else: if fm_current_section == sect["leaf-pile-up"]: print \ """As you rake the leaves, they all fall onto the road and the leaf truck sends them away. Your sister says, "Wow, thank you for raking the leaves for us! I thought it would take me all day to rake leaves and finish my homework from last week. Once I find more leaves, I might as well decorate the house out of them! Then you can take a look at that decoration. Then there's one last moral to this: 'The Amount of Leaves that fall in the Fall'." """ try: for note in [(0, 2), (12, 4), 10, 7, 10, 7, 5, 3, 5, 3, 5, 7, 5, 3, 0, -2, 0, 3, 0, -2, (0, 5), 0, 3, 4]: if isinstance(note, tuple): pitch = note[0] ms = note[1] * 250 else: pitch = note ms = 250 winsound.Beep(int(440*h**pitch), ms) except Exception, e: print "WinsoundError: %s" % e fm_showSign() try: for note in [(5, 5), 0, 3, 4, 5, 4, 5, 7, 10, 8, 7, 5, 3, 0, 3, 5, 3, 0, -2, 2, (0, 8)]: if isinstance(note, tuple): pitch = note[0] ms = note[1] * 250 else: pitch = note ms = 250 winsound.Beep(int(440*h**pitch), ms) except Exception, e: print "WinsoundError: %s" % e print \ """Congratulations! You have won. Type 'restart' to restart, or 'quit' to turn it off.""" fm_dead = True fm_items[fm_current_section] = [] else: print "You can't rake them here." else: print "You can't rake that." def fm_leave(args): global fm_dead if fm_current_section != sect["leaf-pile-up"]: print "You can't do such a thing." else: print \ """You wave goodbye to the family and start to walk on the sidewalk, following that trail of leaves and seeing where they end up. You soon notice that you have been walking for a long time, and the leaves start looking like they're sticking to the ground. You do appear to be sad to leave your cottage, but you seem to be curious where the trail of leaves is going. Following, following, will the leaves ever come to an end? ...""" try: for note in [(0, 2), (12, 4), 10, 7, 10, 7, 5, 3, 5, 3, 5, 7, 5, 3, 0, -2, 0, 3, 0, -2, (0, 5), 0, 3, 4]: if isinstance(note, tuple): pitch = note[0] ms = note[1] * 250 else: pitch = note ms = 250 winsound.Beep(int(440*h**pitch), ms) except Exception, e: print "WinsoundError: %s" % e fm_showSign() try: for note in [(5, 5), 0, 3, 4, 5, 4, 5, 7, 10, 8, 7, 5, 3, 0, 3, 5, 3, 0, -2, 2, (0, 8)]: if isinstance(note, tuple): pitch = note[0] ms = note[1] * 250 else: pitch = note ms = 250 winsound.Beep(int(440*h**pitch), ms) except Exception, e: print "WinsoundError: %s" % e print \ """Congratulations! You have won. Type 'restart' to restart, or 'quit' to turn it off.""" fm_dead = True fm_items[fm_current_section] = [] def fm_count(args): if fm_current_section != sect["se-nw-road"]: print "You can't do such a thing." else: print "There are about 15 tigers to the northeast." def fm_take(args): if args == []: print "Take what?" else: if not args[0] in obj: print "There is no %s here." % args[0] else: objnum = obj[args[0]] if not objnum in fm_items[fm_current_section]: print "There is no %s here." % args[0] else: if objnum < 0: print "You can't take that." else: print "Taken. " fm_items[fm_current_section].remove(objnum) fm_inventory.append(objnum) def fm_use_objs(obj1, obj2): global fm_on, fm_current_section, fm_jar_objs if obj1 == obj2: print "You can't use anything on itself." else: if obj1 == obj["gas"]: if fm_current_section == sect["se-nw-road"]: fm_move(["northeast"]) else: print "There is no use of that here." elif obj1 == obj["rake"]: if fm_current_section == sect["leaf-pile-up"]: fm_rake(["leaves"]) else: print "There is no use of that here." elif obj1 == obj["flashlight"]: print "You turn the flashlight on." fm_on = True if fm_current_section == sect["grue-darkness"]: fm_current_section = sect["light-darkness"] elif obj1 == obj["jar"]: if not obj2 is None: if fm_jar_objs == 2: print "There is no room left." else: if obj2 == obj["nitric"]: print "You stick the nitric acid in the jar. It fits perfectly." fm_jar_objs += 1 fm_inventory.remove(obj2) elif obj2 == obj["glycerine"]: print "You stick the glycerine in the jar. It fits perfectly." fm_jar_objs += 1 fm_inventory.remove(obj2) else: print "You stick the object in the jar. It doesn't fit at all." else: if fm_jar_objs < 2: print "The jar is not explosive enough to break a hole." else: if fm_current_section in [sect["e-s-corner"], sect["thick-ground"], sect["s-w-thick-ground"]]: print "The jar is too weak to break a hole!" elif fm_current_section == sect["thin-ground"]: fm_drop(["jar"]) else: print "There is no use of that here." else: if obj2 is None: print "You cannot use %s." % fm_reg_objs[obj1][1].lower() else: print "You cannot use %s on %s." % (fm_reg_objs[obj2][1].lower(), fm_reg_objs[obj1][1].lower()) def fm_use(args): global fm_bridge_built, fm_hole if args == []: print "Use what?" else: if not args[0] in obj: print "You do not have %s." % args[0] else: objnum = obj[args[0]] if not objnum in fm_inventory: print "You do not have %s." % args[0] else: if not "with" in args and not "on" in args: fm_use_objs(objnum, None) else: if (args[-1] == "with" and args.count("with") == 1) or (args[-1] == "on" and args.count("on") == 1): print "Use %s %s what?" % (args[0], args[-1]) else: main_trial = None for i in xrange(0, len(args) - 1): if main_trial is None and (args[i] == "with" or args[i] == "on"): main_trial = args[i + 1] if not main_trial in obj: print "You can't see %s." % main_trial else: objnum2 = obj[main_trial] if not objnum2 in fm_inventory and not objnum2 in fm_items[fm_current_section]: print "You can't see %s." % main_trial else: fm_use_objs(objnum2, objnum) def fm_drop(args): global fm_bridge_built, fm_hole, fm_current_section if args == []: print "Must specify an object." else: if not args[0] in obj: print "You do not have that." else: objnum = obj[args[0]] if not objnum in fm_inventory: print "You do not have that." else: if objnum == obj["part"] and fm_current_section == sect["subway-station-south"]: print "The man thanks you and attaches the bridge part to the bridge." fm_bridge_built = True fm_inventory.remove(objnum) elif objnum == obj["jar"] and fm_jar_objs == 2: print \ """The jar immediately explodes into a million pieces the moment it impacts the ground.""" fm_inventory.remove(objnum) if fm_current_section == sect["thin-ground"]: print "The explosion breaks a hole in the ground which you fall through." fm_hole = True fm_current_section = sect["southern-tunnel"] else: print "Done." fm_inventory.remove(objnum) fm_items[fm_current_section].append(objnum) def fm_examine(args): if args == []: fm_explainLong() #Describe when `look' is generated. else: if not args[0] in obj: print "You can't see that." else: objnum = obj[args[0]] if not objnum in fm_inventory and not objnum in fm_items[fm_current_section]: print "You can't see that." else: if objnum == obj["flashlight"]: if not fm_on: print "A normal flashlight. Its lamp is turned off." else: print "A normal flashlight. Its lamp is turned on." else: if objnum < 0: print fm_perm_obj_descr[-objnum] else: print fm_reg_obj_descr[objnum] def fm_give(args): ##You can give stuff if there are people. if not fm_current_section in [sect["subway-station-south"], sect["container-store"], sect["cottage-front"]]: print "You can't do such a thing." else: fm_drop(args) def fm_watch(args): if fm_current_section != sect["your-house"]: print "You can't do such a thing." else: print "You watch the television for a while. Isn't Family Memory a relief!" def fm_sleep(args): if fm_current_section != sect["your-house"]: print "You try to do that while standing up here, but can't seem to do it." else: print "You lie down on the sofa for a while. Oh, how tiring Family Memory is!" def fm_talk(args): global fm_jar_gotten if fm_dead: print "You can't do such a thing." else: if fm_current_section == sect["subway-station-south"]: if not fm_bridge_built: print \ """-Ah, I'm afraid I left the other part of the bridge in a tiger's cage this morning. Could you please go get it for me?""" else: print "-Ah, those tigers die so easily." elif fm_current_section == sect["container-store"]: if not fm_jar_gotten: print \ """-Hello, adventurer. You look like you want something. Here's a glass jar. Received a glass jar!""" fm_jar_gotten = True fm_inventory.append(obj["jar"]) else: print "-Well, how's it doing?" elif fm_current_section == sect["cottage-front"]: print \ """You look up at your family and they say: -Hey there! I was wondering about all off the leaves in the yard. The fall season must have passed. I wonder if the leaves can get into shape. Don't you agree? -I do agree. Also, isn't it amazing thatt there are brown leaves at the end of every fall season? I just wish I could draw brown leaves in a spiral notebook. What do you think? Should we go ahead and draw brown leaves in a spiral notebook? -Well, we'll see about that; it's about ttime for us to go back and finish raking those leaves. Every volunteer rakes leaves sometimes. -Uhh, but I don't remember what the leavees look like; if we're going to draw them, we can't draw them /after/ we rake them! The last time I drew leaves, I was at school, and the teacher showed me how ... and I forgot! Aww!! Isn't it a good thing to have an interesting childhood? """ else: print "You can't do such a thing." def fm_saveVal(variable): return "%s = %s\n" % (variable, eval(variable)) def fm_saveGame(args): if args == []: print "You must supply a filename." else: try: game = open("c:\\documents and settings\\nick\\desktop\\metadunnet[]\\saved games\\family memory\\%s.txt" % args[0], "w") game.write(fm_saveVal("fm_hole")) game.write(fm_saveVal("fm_on")) game.write(fm_saveVal("fm_bridge_built")) game.write(fm_saveVal("fm_jar_gotten")) game.write(fm_saveVal("fm_dead")) game.write(fm_saveVal("fm_quitted")) game.write(fm_saveVal("fm_jar_objs")) game.write(fm_saveVal("fm_current_section")) game.write(fm_saveVal("fm_visited")) game.write(fm_saveVal("fm_inventory")) game.write(fm_saveVal("fm_items")) game.close() except Exception, error: print "Error saving to file." def fm_restoreGame(args): global fm_hole, fm_on, fm_bridge_built, fm_jar_gotten, fm_dead, fm_quitted, fm_jar_objs, fm_current_section, \ fm_visited, fm_inventory, fm_items if args == []: print "You must supply a filename." else: try: restored = open("c:\\documents and settings\\nick\\desktop\\metadunnet[]\\saved games\\family memory\\%s.txt" % args[0], "r") command = \ """global fm_hole, fm_on, fm_bridge_built, fm_jar_gotten, fm_dead, fm_quitted, fm_jar_objs, fm_current_section, \ fm_visited, fm_inventory, fm_items """ for line in restored: trial = line + " " * 25 if trial[0:21] == "fm_current_section = ": if fm_current_section == eval(trial[21:len(line)]): fm_explainShort() command = command + line exec command except Exception, error: print "Could not load restore file." def fm_help(args): print \ """Welcome, adventurer! We're so glad you could join us. Here are some game commands: quit - Turns the game off restart - Restarts the game save - Saves the game restore - Restores a saved game Note that this game /should/ work in a DOS window! We wish you good luck, and hope you enjoy this game! """ fm_verblist = { "help": fm_help, "quit": fm_quit, "restart": fm_restart, "save": fm_saveGame, "restore": fm_restoreGame, "take": fm_take, "drop": fm_drop, "toss": fm_drop, "throw": fm_drop, "give": fm_give, "go": fm_move, "north": fm_north, "south": fm_south, "east": fm_east, "west": fm_west, "n": fm_north, "s": fm_south, "e": fm_east, "w": fm_west, "northeast": fm_northeast, "northwest": fm_northwest, "southeast": fm_southeast, "southwest": fm_southwest, "ne": fm_northeast, "nw": fm_northwest, "se": fm_southeast, "sw": fm_southwest, "up": fm_up, "down": fm_down, "u": fm_up, "d": fm_down, "in": fm_in, "out": fm_out, "enter": fm_in, "exit": fm_out, "rake": fm_rake, "leave": fm_leave, "count": fm_count, "watch": fm_watch, "sleep": fm_sleep, "lie": fm_sleep, "sit": fm_sleep, "talk": fm_talk, "speak": fm_talk, "use": fm_use, "l": fm_examine, "look": fm_examine, "x": fm_examine, "examine": fm_examine, "read": fm_examine, "describe": fm_examine, "inventory": fm_inven, "i": fm_inven, "die": fm_serious, "warp": fm_serious, "setenv": fm_serious, "getenv": fm_serious } def fm_showSign(): print \ """ ******************************************************************************* * * * @@@@@ @ @ @ @ * * @ @ @ @ * * @ @ @@ @@ * * @ @@@ @@@ @@ @ @ @ @ @@ @@ @@@ @@@ @@ @@@ @@ @ @ * * @@@@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ * * @ @@@@ @ @ @ @ @ @ @ @ @ @ @ @@@@@ @ @ @ @ @ @ @ @ * * @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ * * @ @ @ @ @ @ @ @ @@ @ @ @ @ @ @ @ @ @ @ @ @@ * * @ @@@@ @ @ @ @ @ @ @ @ @@@ @ @ @ @@@ @ @ * * @ @ * * @@ @@ * * * ******************************************************************************* (c) Nicholas Chen McConnell started 12/30/10 """ fm_showSign() try: for note in [(0, 2), (12, 4), 10, 7, 10, 7, 5, 3, 5, 3, 5, 7, 5, 3, 0, -2, 0, 3, 0, -2, (0, 8)]: if isinstance(note, tuple): pitch = note[0] ms = note[1] * 250 else: pitch = note ms = 250 winsound.Beep(int(440*h**pitch), ms) except Exception, e: print "WinsoundError: %s" % e #Now refer to the verblist. Explain at any new section. fm_last_section = -1 while not fm_quitted: if not fm_current_section == fm_last_section: #Has it changed from the last? fm_explainIfNew() fm_last_section = int(fm_current_section) reply = raw_input(" ").lower().split() if reply == []: print "Do what?" else: for i in fm_ignore: #Remove ignored words. while i in reply: reply.remove(i) if reply == []: reply = [""] if not reply[0] in fm_verblist: print "You can't do such a thing." else: function = fm_verblist[reply[0]] argset = reply[1:len(reply)] function(argset)