#!/usr/bin/env python ## You should try this one: print \ """METADUNNET[4] ("FLU CURE") by Nicholas McConnell You come home from evening gym class with the flu. It is late at night, and you have planned to go on a walk tomorrow morning. You feel like you need a drink before going to sleep. First time players play, they may wish to help. """ import os ## Descriptions of sections visited = [] sections = [ ( """You are in your living room. There is a sofa and a soft chair here. The rest of the house leads to the northwest. The soft chair is here for your kitty cat.""", "Living room"), #0 ( """You are at the corner of the house. There is a kitchen to the west and a living room to the southeast. Stairs lead up toward the north from here. To the south is your basement.""", "House corner"), ( """You are in a kitchen. There are cupboards and a refrigerator near you. However, the cupboards are locked. The front is to the south, and the rest of the house is to the east. There is a sink in front of you.""", "Kitchen"), ( """You are at the front of the house. A kitchen is to the north and the front door is to the south.""", "House front"), ( """You are at the top of the staircase. The stairs go down toward the south, and bedrooms are to the north, east, and west.""", "Top of staircase."), ( """You are in your bedroom. There is a cozy bed near you, and your bathroom is to the northeast. The door out is to the west.""", "Your bedroom"), #5 ( """You are in your bathroom. There is a toilet, sink, and shower here. Your bedroom is to the southwest.""", "Your bathroom"), ( """You are in Nathan's bedroom. There is a twin bed near you, and the bathroom is to the northeast. The door out is to the south.""", "Nathan's bedroom"), ( """You are in your parent's bedroom. There is a bed here twice as large as yours. The bathroom is to the northwest; the door out to the east.""", "Parent's bedroom"), ( """You are at the front door of your house. The entrance is to the north, and the driveway is to the east.""", "Front door"), ( """You are on the driveway of your house. The front door is to the west, and the road goes to the north. A car is here.""", "Driveway"), #10 ( """You are at the west end of a long path going E/W.""", "West end of long E/W path"), ( """You are 4/5 towards the west end of the passageway.""", "4/5 West"), ( """You are 3/5 towards the west end of the passageway.""", "3/5 West"), ( """You are 3/5 towards the east end of the passageway.""", "3/5 East"), ( """You are 4/5 towards the east end of the passageway. A road forks to the northeast.""", "4/5 East"), #15 ( """You are at the east end of the long path. This is a dead end; you can go back west.""", "East end of long E/W path"), ( """You are on a corner where roads go off to the north and southwest.""", "N/SW corner"), ( """You are at the south side of a large fissure to the north of you. The fissure looks pretty wide and deep. You can also go back south.""", "South side of fissure"), ( """You are on the bridge, in the middle of the fissure.""", "Fissure"), ( """You are at the north side of the fissure; the path continues north.""", "North side of fissure"), #20 ( """You are on a corner where roads go off to the south and northwest.""", "S/NW corner"), ( """You are at the top of a hill. You see your family down below. The path you have been walking on lies to the southeast.""", "Top of hill")] ## Map that helps us determine which ways to go. ## A direction yielding 99 means that the move is special. north = 0 south = 1 east = 2 west = 3 northeast = 4 northwest = 5 southeast = 6 southwest = 7 up = 8 down = 9 _in = 10 out = 11 # n s e w ne nw se sw u d in out dungeon_map = [[-1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1], #0 [ 4, 99, -1, 2, -1, -1, 0, -1, 4, -1, -1, -1], #1 [-1, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1], #2 [ 2, 99, -1, -1, -1, -1, -1, -1, -1, -1, -1, 99], #3 [ 7, 1, 5, 99, -1, -1, -1, -1, -1, 1, -1, -1], #4 [-1, -1, -1, 4, 6, -1, -1, -1, -1, -1, -1, 4], #5 [-1, -1, -1, -1, -1, -1, -1, 5, -1, -1, -1, 5], #6 [-1, 4, -1, -1, 99, -1, -1, -1, -1, -1, -1, 4], #7 [-1, -1, 4, -1, -1, 99, -1, -1, -1, -1, -1, 4], #8 [ 3, -1, 10, -1, -1, -1, -1, -1, -1, -1, 3, -1], #9 [99, -1, -1, 9, -1, -1, -1, -1, -1, -1, 99, -1], #10 [-1, -1, 12, -1, -1, -1, -1, -1, -1, -1, -1, -1], #11 [-1, -1, 13, 11, -1, -1, -1, -1, -1, -1, -1, -1], #12 [-1, -1, 14, 12, -1, -1, -1, -1, -1, -1, -1, -1], #13 [-1, -1, 99, 13, -1, -1, -1, -1, -1, -1, -1, -1], #14 [-1, -1, 16, 14, 17, -1, -1, -1, -1, -1, -1, -1], #15 [-1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1, -1], #16 [18, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1], #17 [99, 17, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], #18 [20, 18, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], #19 [21, 19, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], #20 [-1, 20, -1, -1, -1, 22, -1, -1, -1, -1, -1, -1], #21 [-1, -1, -1, -1, -1, 99, 21, -1, -1, 99, -1, -1]] #22 # n s e w ne nw se sw u d in out ## Take a short room description. ## Change all spaces and slashes to dashes. Remove all periods and apostrophes. sec = {} for i in enumerate(sections): roomname = i[1][1].lower() shortroomname = "" for a in roomname: char = a if char in " /": char = "-" if char in ".'": char = "" shortroomname += char sec[shortroomname] = i[0] ## Objects ## How the user references all objects. obj = {"cup": 0, "dish": 0, "flower": 1, "flowers": 1, "peanut": 2, "peanuts": 2, "bag": 2, "bridge": 3, "food": 4, "yellow": 5, "ball": 5, "papers": 6, "pile": 6, "cassie": -1, "cat": -1, "kitty": -1, "pet": -1, "cupboard": -2, "cupboards": -2, "fridge": -3, "refrigerator": -3, "car": -4, "bed": -5, "sink": -6, "toilet": -7, "shower": -8, "bath": -8, "bathtub": -8, "tub": -8, "elephant": -9, "fissure": -10, "family": -11, "members": -11, "nathan": -12, "brother": -12, "younger": -12, "sofa": -13, "couch": -13} ## Show and describe regular and permanent objects reg_objs = [("There is a cup here.", "A cup"), ("Flowers (already picked) lie on the ground here.", "Some flowers"), ("There is a bag of peanuts here.", "A bag of peanuts"), ("A bridge lies on the ground here.", "A bridge"), ("The refrigerator is open. In it you see tasty food.", "Some food"), ("There is a yellow ball here.", "A yellow ball"), ("There is a pile of papers here.", "A pile of papers")] reg_obj_desc = ["It's a fashioned cup. It shines on your face.", "They are nice spring lilies.", "The peanuts are hard peanuts.", "A bridge that got disconnected from a river.", "Smells good...", "A shiny yellow rubber ball.", "They talk about national wildlife."] perm_objs = [None, "Cassie, the kitty cat, sleeps soundly on the chair.", None, None, None, None, None, None, None, "There is an elephant in your way.", None, "Your family stands, inviting you to get into the car.", "Nathan, your younger brother, lies in the bed, fast asleep.", None] perm_obj_desc = \ [None, "Cassie is sleeping on the chair, softly purring.", "The cupboards are locked.", "A normal white refrigerator.", "It's a normal CAMRY vehicle.", "It is a white bed, with a very cuddly mattress (with the sheets).", "A normal bathroom sink.", "The toilet is usually clean.", "A bathroom shower. You get in there most nights.", "The elephant is about twice as tall as you.", "A DEEP and WIDE fissure!", """The father's in the driver's seat, the mother's packing, and Nathan is standing outside. Cassie, the kitty cat, is in the back seat of the car.""", "Nathan is loving, forgetless, and sound asleep. He also likes video games.", "A 3-seat sofa with a fuzzy outside."] def special_obj_desc(objnum): if objnum == obj["cup"] and cup_filled: print "It's full of water." if objnum == obj["bridge"]: if bridge_folded: print "It's folded closed." else: print "It opens up wide enough to spread in your arms." inventory = [] items = [[obj["sofa"], obj["cassie"]], #0 [obj["ball"]], #1 [obj["cup"], obj["cupboards"], obj["refrigerator"]], #2 [], #3 [obj["papers"]], #4 [obj["bed"]], #5 [obj["sink"], obj["toilet"], obj["shower"]], #6 [obj["bed"], obj["nathan"]], #7 [obj["bed"]], #8 [obj["flowers"]], #9 [obj["car"]], #10 [], #11 [obj["peanuts"]], #12 [], #13 [obj["elephant"]], #14 [], #15 [], #16 [obj["bridge"]], #17 [obj["fissure"]], #18 [obj["fissure"]], #19 [obj["fissure"]], #20 [], #21 []] #22 ## Other properties current_section = 3 game_run = True on_sofa = False in_bed = False night = True cup_filled = False drunk_water = False bridge_folded = True fissure = False gottago = False clean = False brother_sick = False cat_sick = False ## Describe the section def describe(section, lng=False): global visited if on_sofa: print "You are lying on the sofa, facing the ceiling." if obj["cassie"] in items[section]: print "You can hear Cassie purr from here." elif in_bed: if night: print \ """You are lying in your bed. Moonlight shines from the window, bringing light into the room.""" else: print "You are lying in your bed. Sunlight shines from the window." else: if lng and section in visited: visited.remove(section) print sections[section][1] if not section in visited: print sections[section][0] for i in items[section]: if i >= 0: print reg_objs[i][0] else: if isinstance(perm_objs[abs(i)], str): print perm_objs[abs(i)] if not section in visited: visited.append(section) def lose(): global game_run print "\n * YOU HAVE MISSED OUT *" print "Please reload if you would like to restart." game_run = False def win(): global game_run print "\n * CONGRATULATIONS! YOU HAVE WON *" print "Please reload if you would like to restart." game_run = False def _quit(args): global game_run print "Goodbye!" game_run = False def examine(args): args = [x for x in args if not x in ("at", "around")] if args == []: describe(current_section, True) else: objnum = obj_from_args(args) if not objnum is None: if not objnum in inventory and not objnum in items[current_section]: print "You can't see any such thing." else: if objnum >= 0: print reg_obj_desc[objnum] else: print perm_obj_desc[abs(objnum)] special_obj_desc(objnum) def take(args): if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: if len(args) > 0 and args[0] in ("all", "entire", "everything", "whole"): gotsome = False first_objects = list(items[current_section]) for i in first_objects: if i >= 0: gotsome = True print "%s:" % reg_objs[i][1], take_object(i) if not gotsome: print "Nothing here to take." else: objnum = obj_from_args(args) if not objnum is None: take_object(objnum) def take_object(objnum): global inventory, items if not objnum in items[current_section]: print "You can't see any such thing." elif objnum == obj["food"]: print "There's so much; you can't decide what..." elif objnum < 0: print "You can't take /that/!" else: print "Taken." items[current_section].remove(objnum) inventory.append(objnum) def pick(args): take([x for x in args if x != "up"]) def drop(args): if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: if len(args) > 0 and args[0] in ("all", "entire", "everything", "whole"): gotsome = False first_objects = list(inventory) for i in first_objects: if game_run: gotsome = True print "%s:" % reg_objs[i][1], drop_object(i) if not gotsome: print "You have nothing to drop." else: objnum = obj_from_args(args) if not objnum is None: drop_object(objnum) def drop_object(objnum): global inventory, items if not objnum in inventory: print "You don't have that." else: inventory.remove(objnum) if objnum == obj["ball"]: print "The ball bounces softly." if obj["cassie"] in items[current_section]: print "Cassie keeps sleeping, not willing to play." else: print "Done." if objnum == obj["peanuts"] and obj["elephant"] in items[current_section]: print "The elephant takes the peanuts and walks away with them." items[current_section].remove(obj["elephant"]) elif objnum == obj["flowers"] and current_section == sec["top-of-hill"]: print \ """The flowers fall over the hill, and down toward your family. Your family waves and thanks you, and comes to talk to you. When you find them, everyone talks about how everyone gets together. Then you all go home to have lunch.""" win() else: items[current_section].append(objnum) def throw(args): drop([x for x in args if x != "away"]) def put(args): drop([x for x in args if x != "down"]) def get(args): if args and args[0] in ("in", "into", "on", "onto"): get_in(args[1:len(args)]) elif args and args[0] in ("out", "off"): stand([]) elif args and args[0] == "up": wake(args) else: take(args) def get_in(args): global current_section, on_sofa, in_bed objnum = obj_from_args(args) if not objnum is None: if objnum == obj["bridge"] and fissure and current_section in (18, 20): current_section = sec["fissure"] describe(sec["fissure"]) else: if not objnum in items[current_section]: print "You can't see any such thing." else: if objnum == obj["car"]: move(_in) elif objnum == obj["bed"]: if current_section == sec["your-bedroom"]: if in_bed: print "You are already in the bed!" else: print "You hold the covers and tuck yourself under." in_bed = True else: if obj["nathan"] in items[current_section]: print "Nathan is taking up most of the bed." else: print "It would be quite good of you not to lie in someone else's bed!" elif objnum == obj["shower"]: shower([]) elif objnum == obj["fissure"]: print "You jump into the fissure and die. That was a very strange thing to do!" lose() elif objnum == obj["sofa"]: if on_sofa: print "You are already on the sofa!" else: print "You struggle up, and lie down on the sofa." on_sofa = True else: print "I don't recognize a way to get in that object." def lie(args): if obj["bed"] in items[current_section]: get_in(["bed"]) elif obj["sofa"] in items[current_section]: get_in(["sofa"]) else: print "You try to lie down, but you don't feel comfortable." ## You appear to be unable to wake anyone up. ## Whenever anyone's asleep, it's late night and you're sick. ## And so you won't touch them. ## Anyway, it's an awful thing to wake someone up when ## you would rather be asleep yourself. def wake(args): if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: args = [x for x in args if x != "up"] objnum = obj_from_args(args) if not objnum is None: if not objnum in items[current_section]: print "You can't see any such thing." else: if objnum == obj["cassie"]: print "I'm afraid Cassie's eyes did not once open. You're sick, anyway." elif objnum == obj["nathan"]: print \ """Nathan rolls over and keeps sleeping, totally subconscious. You're sick anyway; you wouldn't try to touch him.""" elif objnum == obj["family"]: print "The family is already awake!" else: print "You cannot wake that up." def stand(args): global on_sofa, in_bed if on_sofa: if night: print "You get off the sofa, as an ill person." else: print "You get off the sofa." on_sofa = False elif in_bed: if night: print "You get out of bed, as a sick person." else: print "You get out of bed." in_bed = False else: print "You're already standing up." ## Note: ## If the sofa was a sectional, you could pull out a sofa bed ## (if you felt like it). ## You have to be very careful that THERE IS NO HARM IN THE MORNING. ## It's even sudden if you accidentally urinate on the bed at 1:30 AM. ## Maybe you touched someone else! MAYBE CASSIE HAS RAN AWAY! ## Maybe you didn't drink, so you were still sick! ## BE CAREFUL! def sleep(args): global night, gottago, items if on_sofa: if night: print \ """You try to, but only two minutes pass. You shiver with the flu, and you have no blankets.""" else: print "I'm afraid that you don't appear to be tired." elif in_bed: if night: if not gottago and not obj["cassie"] in items[sec["living-room"]]: print \ """You rest your head against the pillow, close your eyes, and fall asleep. The next morning, Nathan walks into your room. He tells you that the pet cat is missing, and you apologize about it. It turns out that Cassie can hardly be fed now that none of you know where she is. Ah well, maybe find the cat now, and go on a walk next week.""" lose() elif not gottago and brother_sick: print \ """You rest your head against the pillow and fall fast asleep. The next morning, your parents walk into your room. They tell you that Nathan is sick in bed, but - none of you want to leave him alone all morning! It would be wise to take care of Nathan now and save the walk for later.""" lose() elif not gottago and cat_sick: print \ """You rest your head against the pillow, close your eyes, and fall asleep. The next morning, Nathan walks into your room. He tells you that the pet cat has the flu now! This is unbelievable. You all better take care of the cat now and save the walk for later. Aww...""" lose() elif not drunk_water: print \ """You rest your head against the pillow and fall asleep. The next morning, Nathan walks into your room. Unfortunately, it's time to go on the walk, and you're still sick. Ah well, maybe a drink of water and another nap, and promise to come next week.""" lose() elif gottago: print \ """You rest your head against the pillow and fall asleep. You peacefully sleep until you realize that you accidentally urinate on the bed. It's 1:30 in the morning, and no one nearby is awake to help you. Perhaps you could roll your blanket up and sleep on the rug.""" lose() else: print \ """You rest your head against the pillow, close your eyes, and fall asleep. The next morning, Nathan walks into your room. He invites you to the walk and you look at him. You are so glad; you've slept off all your sickness during the night, and you're feeling good! Nathan leaves.""" night = False items[sec["nathans-bedroom"]].remove(obj["nathan"]) items[sec["living-room"]].remove(obj["cassie"]) items[sec["driveway"]].append(obj["family"]) gottago = True else: print "You feel really comfortable, but you don't appear to be tired." else: if night: print "You try to sleep off the flu while standing here, but appear to be unable to." else: print "You try to sleep while standing here, but you appear to be unable to." def eat(args): global inventory objnum = obj_from_args(args) if not objnum is None: if not objnum in inventory: print "You don't have that." else: if objnum == obj["peanuts"]: print "You eat the peanuts and eject the bag." inventory.remove(obj["peanuts"]) elif objnum == obj["food"]: print "Which food?" else: print "That is plainly inedible." def hit(args): global inventory if args and args[0] in ("me", "myself", "self", "my"): print "You hurt a little bit. Nothing obvious happens." else: objnum = obj_from_args(args) if not objnum is None: if not objnum in items[current_section] and not objnum in inventory: print "You can't see any such thing." else: if objnum == obj["nathan"]: print \ """Nathan wakes up suddenly. His right arm is injured, and he's crying. He wipes his eyes on the pillow. You look at him at start to get upset as well. You feel like he needs to go to the hospital - but - this is a disaster. A total disaster. Nathan would feel /awful/ if you took him out of bed. Maybe you could go shopping for bandages - with the flu? No way! YOU ARE IN BIG TROUBLE NOW.""" lose() elif objnum == obj["cassie"]: print \ """Cassie outright wakes up, and whines so loudly that you feel like you have to plug your ears. She runs around the room, whining like a wolf. I don't even think it's easy for her to run around, now that her paw is injured.""" if obj["nathan"] in items[sec["nathans-bedroom"]]: print \ """Your brother, Nathan, upstairs, awakens from his sleep and runs down. He gently places the cat on the chair and whispers, "It's okay, Cassie. It's okay, don't worry." But it's hardly okay. You NEVER injure your pet cat again!""" lose() elif objnum == obj["family"]: print "That certainly would not be a wise thing to do at all!" else: print "Nothing obvious happens." def hug(args): global brother_sick, cat_sick if args and args[0] in ("me", "myself", "self", "my"): print "Nothing obvious happens." else: objnum = obj_from_args(args) if not objnum is None: if not objnum in items[current_section] and not objnum in inventory: print "You can't see any such thing." else: if objnum == obj["nathan"]: print "Nathan coughs once, but remains in sleep." brother_sick = True elif objnum == obj["cassie"]: print "Cassie's forehead becomes warmer. She continues to sleep hopefully." cat_sick = True elif objnum == obj["family"]: print "That's nice; but for what? They didn't help you get better." else: print "Nothing obvious happens." def quaff(args): global drunk_water, cup_filled, gottago if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: if obj["cup"] in inventory and cup_filled: print "You drink up the water. Ahh!" cup_filled = False drunk_water = True gottago = True else: print "You have nothing that you can quaff." def pour(args): global drunk_water, cup_filled, gottago if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: if obj["cup"] in inventory and cup_filled: print "You pour the water on the ground; but why?" if obj["cat"] in items[current_section]: print "Cassie wakes up and purrs. She runs away from the spill." items[current_section].remove(obj["cat"]) if obj["nathan"] in items[current_section]: print \ """Nathan wakes up and looks at the spill. You tell him that it's okay, and he goes back to sleep.""" cup_filled = False else: print "You have nothing that you can pour." def yell(args): if night: print "As a person with the flu, it's hard to yell very loudly." if obj["cat"] in items[current_section]: print \ """However, your yell is quite a bit loud. Cassie wakes up suddenly, meows, and runs out of sight.""" items[current_section].remove(obj["cat"]) if obj["nathan"] in items[current_section]: print \ """However, your yell is quite a bit loud. Nathan awakens and whispers, "Geez, why are you awake and yelling when it's after 10:00?! You seriously interrupted my dream!" You apologize to him, and you feel bad. You tell him that it's alright. He pulls up the covers, and lies back down in sleep.""" else: print "You give a very loud yell." if obj["family"] in items[current_section]: print "Nathan says, \"Could you please lower your voice!!\" Your mother stares at you." def _help(args): print \ """METADUNNET[4] ("FLU CURE") by Nicholas McConnell Welcome! We would like to give you a few tips about the game: -You can use semicolons to separate commandds, i.e. inputting 'look cup; drink' does the same thing as inputting 'look cup', hitting ENTER, and then inputting 'drink'. This can allow execution of multiple commands at once. -If you spot anyone sleeping, remember thatt it's late at night, and don't try to wake them up. They could get your illness. Also, you can't basically move around until it's daytime. Daytime will never come until you actually go to bed. That means, you can just move around as long as you want, and they'll still be sleeping. You actually can't /wait/ for anything in most metadunnet games. Usually no other people are involved. -'put' is only recognized as 'drop' and 'piick' is only recognized as 'take'. So, try not to use 'put' when attaching or combining objects. This is a current warning - without this your score could be damaged. -When you're sick, you should be able to goo to sleep. If that doesn't work, try doing something else beforehand. -You do not have to explicitly open any of the doors; you can just walk in. However, if you want to lie down somewhere, you need to explicitly lie down and get up. I know whether you're in bed or just standing in your room, if you're in your room. -You can save a game with the 'save' commannd, and restore it with the 'restore' command. -Directions are: north, south, east, west, northeast, northwest, southeast, southwest, up, down, in, out. -These can be abbreviated: n, s, e, w, ne, nw, se, sw, u, d, in, out. -It is a good habit not to talk when it's llate night and you're sick. -Try not to jump over most things. -This game /should/ be run in a DOS window!! If you have any questions or comments, please contact http://www.bluzeandmuse.com/ and click on the Games link. """ def inven(args): if inventory == []: print "You currently have nothing." else: for i in inventory: print "You currently have %s." % reg_objs[i][1].lower() def _open(args): global items, bridge_folded if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: objnum = obj_from_args(args) if not objnum is None: if not objnum in inventory and not objnum in items[current_section]: print "You can't see any such thing." else: if objnum == obj["flowers"]: print "Nothing happens." elif objnum == obj["bag"]: print "The bag is already open!" elif objnum == obj["bridge"]: if bridge_folded: print "You open the bridge up." bridge_folded = False else: print "The bridge is already open!" elif objnum == obj["papers"]: print "Nothing happens." elif objnum == obj["cupboards"]: print "The cupboards are locked." elif objnum == obj["refrigerator"]: if obj["food"] in items[current_section]: print "The refrigerator is already open!" else: print "You open the refrigerator." items[current_section].append(obj["food"]) else: print "I don't know how to open that." def close(args): global items, bridge_folded if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: objnum = obj_from_args(args) if not objnum is None: if not objnum in inventory and not objnum in items[current_section]: print "You can't see any such thing." else: if objnum == obj["flowers"]: print "Nothing happens." elif objnum == obj["bag"]: print "The bag can't be closed like that." elif objnum == obj["bridge"]: if bridge_folded: print "You fold the bridge again." bridge_folded = False else: print "The bridge is already folded!" elif objnum == obj["papers"]: print "Nothing happens." elif objnum == obj["cupboards"]: print "The cupboards are already closed." elif objnum == obj["refrigerator"]: if not obj["food"] in items[current_section]: print "The refrigerator is already closed!" else: print "You close the refrigerator." items[current_section].remove(obj["food"]) else: print "I don't know how to close that." def feed(args): if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: objnum = obj_from_args(args) if not objnum is None: if not objnum in items[current_section]: print "You can't see any such thing." else: if objnum == obj["elephant"]: if not obj["peanuts"] in inventory: print "You have nothing in which to feed it." else: drop(["peanuts"]) elif objnum == obj["family"]: print "How are you going to feed your family like this?" elif objnum == obj["nathan"]: print "But Nathan is asleep." elif objnum == obj["cassie"]: print "But the cat is asleep." else: print "You can't feed that!" ## The following are other single commands def fill(args): global cup_filled if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: if not obj["cup"] in inventory: print "You have nothing to fill." elif not current_section in (sec["kitchen"], sec["your-bathroom"]): print "There is nothing here in which you can fill the cup." elif cup_filled: print "The cup is already full of water." else: print "You fill the cup with warm water." cup_filled = True ## I know this is an awful topic! def piss(args): global gottago if current_section != sec["your-bathroom"]: print "You can't do such a thing here; don't even bother trying." else: if not gottago: print "I don't think you have to go now." else: print "Done. You then flush the toilet." gottago = False def shower(args): global clean if current_section != sec["your-bathroom"]: print "You can't shower here!" else: if clean: print "You are already clean!" else: if night: print "You don't feel like getting in the shower. You have the flu." else: print "You take a shower, dry yourself off, and dress again." clean = True def jump(args): if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: if not current_section in (18, 20): print "Nothing happens." else: if current_section == 18: move(north) else: move(south) def talk(args): if obj["nathan"] in items[current_section]: print "But Nathan is asleep." elif obj["family"] in items[current_section]: print \ """You all talk about how interesting the walk is going to be. You're lucky to be on the driveway.""" elif current_section == sec["top-of-hill"]: print "Your parents are too far down to hear you!" else: print "Nothing happens." def bridge(args): global inventory, fissure if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: if not current_section in (18, 20): print "I don't know what you can bridge." else: if not obj["bridge"] in inventory: print "But you don't have a bridge." else: if bridge_folded: print "The folded bridge doesn't reach all the way across the fissure." else: print "You spread the bridge across the fissure, walking on it in the process." inventory.remove(obj["bridge"]) fissure = True def move_north(args): move(north) def move_south(args): move(south) def move_east(args): move(east) def move_west(args): move(west) def move_northeast(args): move(northeast) def move_northwest(args): move(northwest) def move_southeast(args): move(southeast) def move_southwest(args): move(southwest) def move_up(args): move(up) def move_down(args): move(down) def move_in(args): move(_in) def move_out(args): move(out) ## Remember: 99 is special def move(direct): global current_section if direct == out and (on_sofa or in_bed): stand([]) else: if on_sofa: print "You'll have to get off the sofa first." elif in_bed: print "You'll have to get out of bed first." else: osection = int(current_section) newroom = dungeon_map[current_section][direct] if newroom == -1: print "You can't go there." elif newroom == 99: special_move(direct) else: current_section = newroom if osection != current_section: describe(current_section) ## Move is special - can't go there unless certain conditions meet, etc. def special_move(direct): global current_section if current_section == sec["house-corner"]: print "I find no reason for you to go into your basement now." elif current_section == sec["house-front"]: if night: print "It's too cold and dangerous of a night for a sick person to go out." else: current_section = sec["front-door"] elif current_section == sec["top-of-staircase"]: if night: print "It would be altogether nicer behavior to not disturb your parents at night." else: current_section = sec["parents-bedroom"] elif current_section == sec["nathans-bedroom"]: print "You shouldn't walk into someone else's bathroom without a reason." elif current_section == sec["parents-bedroom"]: print "You shouldn't walk into someone else's bathroom without a reason." elif current_section == sec["driveway"]: if direct == north: print "It's not safe to walk on the road like that!" else: print \ """You get into the car and the drive starts. The car drives halfway there and then ...""" if not clean: print "You smell yourself and choke." if gottago: print "You suffer, needing to use the bathroom." if not clean or gottago: print "Because of that, time is being wasted. Ah well, maybe next week." lose() else: print \ """Nothing bad happens. The car continues driving. Pretty soon your family arrives. They drop you off at a certain spot and leave on their own.""" current_section = sec["west-end-of-long-e-w-path"] elif current_section == sec["3-5-east"]: if obj["elephant"] in items[current_section]: print "The elephant is blocking your path." else: current_section = sec["4-5-east"] elif current_section == sec["south-side-of-fissure"]: if not fissure: print "You didn't make it to the end. You fall on the bottom and there you die." lose() else: current_section = sec["fissure"] elif current_section == sec["top-of-hill"]: print "The hill is far to steep to walk down there." ## Game and run controls below; and adventure controls above. def obj_from_args(args): if args == []: print "You must supply an object." elif not args[0] in obj: print "I don't recognize what that object is." else: return obj[args[0]] def restore(args): if args == []: print "You must supply a filename." else: try: exec open("saved games\\metadunnet4\\%s.txt" % args[0]) print "Done." describe(current_section) except Exception: print "Could not load restore file." def save(args): if args == []: print "You must supply a filename." else: try: if not os.access("saved games", os.F_OK): os.mkdir("saved games") savepath = os.path.join("saved games", "metadunnet4") if not os.access(savepath, os.F_OK): os.mkdir(savepath) game = open(os.path.join(savepath, "%s.txt" % args[0]), "w") game.write(save_val("visited")) game.write(save_val("inventory")) game.write(save_val("items")) game.write(save_val("current_section")) game.write(save_val("on_sofa")) game.write(save_val("in_bed")) game.write(save_val("night")) game.write(save_val("cup_filled")) game.write(save_val("drunk_water")) game.write(save_val("bridge_folded")) game.write(save_val("fissure")) game.write(save_val("gottago")) game.write(save_val("clean")) game.write(save_val("brother_sick")) game.write(save_val("cat_sick")) print "Done." except Exception: print "Error saving to file." def save_val(varname): return "global %s\n%s = %s\n" % (varname, varname, `eval(varname)`) def awful(args): print "That is an awful thing to even try to do!" def wave(args): if current_section == sec["top-of-hill"]: print "You wave at your family and they wave back." else: if obj["family"] in items[current_section]: print "Why do you want to wave at your family now?" else: print "Nothing happens." verblist = {"pick": pick, "take": take, "get": get, "drop": drop, "throw": throw, "put": put, "toss": drop, "look": examine, "l": examine, "examine": examine, "x": examine, "read": examine, "describe": examine, "eat": eat, "devour": eat, "consume": eat, "quaff": quaff, "drink": quaff, "sleep": sleep, "lie": lie, "stand": stand, "doze": sleep, "wake": wake, "inventory": inven, "items": inven, "i": inven, "help": _help, "?": _help, "quit": _quit, "n": move_north, "north": move_north, "s": move_south, "south": move_south, "e": move_east, "east": move_east, "w": move_west, "west": move_west, "ne": move_northeast, "northeast": move_northeast, "nw": move_northwest, "northwest": move_northwest, "se": move_southeast, "southeast": move_southeast, "sw": move_southwest, "southwest": move_southwest, "u": move_up, "up": move_up, "climb": move_down, "d": move_down, "down": move_down, ## 'fall' is crazy! "fall": move_down, "in": move_in, "out": move_out, "enter": move_in, "exit": move_out, "on": move_in, "off": move_out, "restore": restore, "save": save, "open": _open, "close": close, "fill": fill, "piss": piss, "urinate": piss, "shower": shower, "use": piss, # another idea "clean": shower, "jump": jump, "talk": talk, "speak": talk, ## Look before you leap "leap": jump, "feed": feed, "bridge": bridge, "attach": bridge, "lay": bridge, "unfold": _open, "fold": close, "spread": bridge, "die": awful, "shoot": awful, "getenv": awful, "setenv": awful, "wave": wave, "pour": pour, "scream": yell, "shout": yell, "yell": yell, "yelp": yell, "hit": hit, "pound": hit, "bang": hit, "injure": hit, "slap": hit, "punch": hit, "hug": hug, "embrace": hug, "pat": hug} ## Run the game loop. Split spaces, commas, colons, and semicolons. ## (Semicolons separate /commands/!) ## After each character is chopped, remove any empty strings in the result. def execprint(string): line = string.split() for c in ",:;": line = c.join(line) line = line.split(c) line = [x for x in line if x != ""] if line: go_mode = False while line and line[0] == "go": line.remove("go") go_mode = True if line == []: line.append(str()) if not line[0] in verblist: if not go_mode: print "That's not a command I recognize." else: print "I do not recognize where you want me to go." else: function = verblist[line[0]] argset = line[1:len(line)] function(argset) def run_game(): describe(current_section) while game_run: line = raw_input(">").lower().split(";") first = True for i in line: if game_run: if not first: print ">" execprint(i) first = False if __name__ == "__main__": # __name__ is the current module raw_input() if __name__ == "__main__": run_game()