Thread: Why OOP?
View Single Post
Old Oct 4th, 2007, 2:44 PM   #18
nisim777
Newbie
 
Join Date: May 2005
Posts: 17
Rep Power: 0 nisim777 is on a distinguished road
re:

Here is what I have coded so far. The rest of the game is designed out, just not coded yet. Also, the stuff at the end of my code in the kitchen() function is something I am just playing with. The plan is to make a gameover function that will handle this stuff, I just threw it in there to test it on a whim.

I have no character creation yet. Wasn't really planning on it, but it seems like OOP was built for things like that, so I may add it for practice.

Here's the code:

# Collection Notice

import random

global souls
global encounter
global foySoul
global encounterCount


souls = 0
encounter = 0
foySoul = 0

def help1():
    print """
    Type (without the qoutes):
        'look' to see the room description again.
        'examine (object)' to examine an object.
        'take (item)' to take an item.
        'use (item)' activates and uses items such as lightswitches.
    """

def start():
    print """
            Collection Notice v.1.0
            
        "Life is the jailer, death the angel sent to draw the unwilling bolts 
        and set us free."
            - James Russell Lowell
        
    You are a soul collector. You are charged to see that the dying have an
    uneventful transition into the next life. Because Death is not omnipotent, 
    those mortals indebted to him serve as collectors.
    The Angel of Death has informed you that tonight's task shall be enough
    to repay your debt in full.
        
    You stand before an expansive mansion and note to yourself that it 
    would better be labled a compound. As you step into the front door
    you already know what to expect. Fifty seven people have been massacred
    on this night. You are here to find and collect their souls.
    """
    raw_input("Press enter to continue: ")
    foyer()

def foyer():
    global souls
    global foySoul
    global encounterCount
    print """
    You are in the foyer of the house. The air is thick with death here.
    Humidity has already caught the death stench and it permeates the house.
    The house is dark. On the wall beside the entrance is a light switch.
    
    Directly in front of you is a passage way leading deeper into the house.
    At the far end of the passage way is a window, which allows a bit of
    moonlight to shine into the darkness. On the left and right sides of the
    hallway are small tables. Sitting on the right-hand table is the smiling 
    head of an elderly man, and he seems to be looking at you.
    """
    raw_input("Press enter to continue: ")
    
    print """
    As you look around the foyer you notice a dark shape in the corner.
    AS you slowly walk toward the shape, the face of a small girl dips
    into the dim light of the moon from the doorway. You start back, 
    suprised to see anyone alive in this house.
    "Who are you?" You say.
    The little girl smiles at you. 
    "Yours shall be mine, Soul Collector." Her voice is a mix of an 
    innocent child, and innocence defiled - a growling demonic voice.
    She smiles again and melts into the shadows.
    """
    
    print "Your exits are n, s, e, w"
    foy_prompt()

def foy_prompt():
    global souls
    global foySoul
    choice = raw_input("What would you like to do? ").lower()
    if choice == "s":
        if souls < 57:
            print "You cannot leave this place until you have collected all souls."
            foy_prompt()
    elif choice == "n":
        intersection()
    elif choice == "w":
        kitchen()
    elif choice == "e":
        den()
    elif choice == "use lightswitch":
        print "The light above you flickers for a moment then explodes in a"
        print "shower of sparks."
        foy_prompt()
    elif choice == "examine head":
        if foySoul == 0:
            print "As you peer into the eyes of the decapetated head, you see" 
            print "the tiny shimmering light of a soul lingering deep within."    
            foy_prompt()
        else:
            print "The soul is gone. It is now just a bloody head."
            foy_prompt()
    elif choice == "take soul":
        if foySoul == 0:
            foySoul = 1
            print "You reach into the head and grap the wisp of soul."
            souls = souls + 1
            print "You now have", souls, "souls."
            foy_prompt()
        else:
            print "You have already collected this soul."
    elif choice == "help":
        help1()
        foy_prompt()
    elif choice == "examine":
        print "Examine what?"
        foy_prompt()
    else:
        print "That is an invalid choice. Try something else."
        foy_prompt()

    

def kitchen():
    global encounterCount
    global souls
    global kitchenSouls
    
    print """    You step into a dark kitchen. An dim emergency light is
    glowing above the stove, casting a yellow tint across the room. In the
    center of the kitchen is a small island counter, upon which is a bloody
    knife. The body of a middle-aged man is slumped against the island. There
    is a low hum coming from the garbage disposal in the sink. On the wall is
    an magnetic strip holding a number of knives.
    """
    encounter = random.randrange(100) + 1
    encounterChance = 0
    if (encounter <= 50) and (encounterChance == 0):
        encounterChance = 1
        if encounterCount != 9:
            
            print """   For a brief moment the light in the room seems to grow
            brighter. A large knife jumps from the knife strip on the wall and
            sails toward you. You lunge out of the way just in time, but it still 
            slices into your arm. As you stand up you hear the laughter of a little
            girl.
            """
        else:
            print """    You feel a cold hand crawling across your back. As you
            turn confront the owner of said had you are paralyzed as the hand
            reaches into your body. You can feel it grasp your soul, tugging. 
            "I told you your's would be mine." The breath of the little girl
            is hot on the knape of your neck.
            "I am darker than death, and his shall be mine soon."
            The girl gives a final tug and all goes dark.
            """
            raw_input("Press enter to continue: ")
            print """   When you awaken you know you are different. You have of
            those with your condition. You are a Souless. You cannot die,
            because Death's punishment to those with no soul is unfathomable.
            You are forced to walk to earth forever, feasting upon the souls of
            the living to remain alive. You know that you will struggle with
            this at first, but survival will override that struggle. But
            eventually, all Souless learn to enjoy the deaths - just like the
            little girl who enjoyed yours.
            
                            You have lost
                            Game Over"""
        encounterCount += 1
    print "Your exits are to the e and w."
    raw_input("What would you like to do? ")
    kit_prompt()
    
    
# encounter = random.randrange(100) + 1
#    encounterChance = 0
#    if (encounter <= 80) and (encounterChance == 0):
#        encounterChance = 1

start()

raw_input("Press enter to exit. ")
nisim777 is offline   Reply With Quote