#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Question IDLE help please! :(


    So today I had to make a text adventure for school. Yay
    Anyways I have to make it so that when you kick the crack in the wall 3 times it should change the description right?
    Well it doesn't. You will understand, just if you could help I would be grateful just one small error I've been stuck on forever. Here is my current state
    Code:
    north=0
    east=1
    south=2
    west=3
    spider = 1
    # The Place class has 3 variables: a description, a list of exits and a list of things.
    # The description and list of things are passed as parameters when a new Place is created;
    # the list of exits is set to None,None,None,None.  (An exit can only be set after the place
    # it links to has been declared.)
    # Place also has one function, describe(), which prints the description.
    class Place:
        def __init__(self,description,things):
            self.description = description
            self.exits=[None,None,None,None]
            self.things=things
        def describe(self):
            print
            print self.description
    kicks = 0
    northside = Place("You're on the north side of the chifferobe",["highshoe","sticker"])    
    middle = Place("You're in the middle of an overly long shifterobe, you notice there are 2 defined sides. There is also a small locked chest on the floor",[])
    southside = Place("You are in the south side of the chifferobe how spookie. You notice a small crack in the wood near the bottom, not big enough to expand with your hands.",[])
    outside =Place("David was too bored to add this bit just go back inside and open the box.",["key"])
    stab = False
    #Then define the exits:
    northside.exits=[None,None,middle,None]
    middle.exits=[northside,None,southside,None]
    southside.exits=[middle,None,None,None]
    outside.exits=[None,None,None,southside]
    
    # The goto function will change the currentplace if the exit in the
    # specified direction is not None.
    def goto(direction):
        global currentplace
        if currentplace.exits[direction]==None:
            print "You cannot go there."
        else:
            currentplace = currentplace.exits[direction]    
    stabspots=[southside]
    # Where you start:
    currentplace = middle
    # Things you start with:
    inventory = []
    # Introductory comments:
    print "You wake up with a really bad headache and a bump on your forehead.\n"
    
    gameOn=True
    while gameOn:
        currentplace.describe()
        if len(currentplace.things)>0:
            print "You see:",
            for item in currentplace.things:
                print item,"  ",
            print
            
        command = raw_input("What do you want to do? ").lower()
        parsed = command.split() # This is a list of the words in command
        if command in ["north","go north"]:
            goto(north)
        elif command in ["south","go south"]:
            goto(south)
        elif command in ["east","go east"]:
            goto(east)
        elif command in ["west","go west"]:
            goto(west)
        elif command in ["quit", "exit", "byebyebubbie"]:
            gameOn=False
        elif command in ["inventory", "inv"]:
            if len(inventory)>0:
                print "You look in your oversized hands and see:",
                for item in inventory:
                    print item,"  ",
                print
        elif parsed[0] in ["get", "take"]:
            del parsed[0] # remove the first word ("get" or "take")
            for item in parsed: # allow getting multiple items
                if item in currentplace.things:
                    inventory.append(item)
                    currentplace.things.remove(item)
                    print "You pick up the", (item)
                    if item == "sticker":
                      print "*\"100% maple\"*"
                    if item == "highshoe":
                      print "*a high heeled shoe, how useful...*"
        elif parsed[0] in ["put", "drop"]:
            del parsed[0] # remove the first word ("put" or "drop")
            for item in parsed: # allow dropping multiple items
                if item in inventory:
                    currentplace.things.append(item)
                    inventory.remove(item)
        elif parsed[0] in ["stab", "kick"] and stab == True and currentplace in stabspots:
            if currentplace == southside and kicks != 3:
                print "You kick the small crack and it becomes larger."
                kicks = kicks + 1  
            if kicks >= 3:
                southside = Place("You have reached the south side of the chifferobe how spookie.The crack on the east side is now just large enough for you to squish through.",[])
                southside.exits=[middle,outside,None,None]
        elif parsed[0] in ["stab", "kick"] and stab == True and currentplace not in stabspots:
            print "No stabbing here man"
        elif currentplace == middle and spider == 2:
            print "You smack the little bugger and he dies, that was melodramatic and you now feel guilty."
            spider == 3
        elif parsed[0] in ["use"]:
            if parsed[1] not in inventory:
                print "You do not have ",parsed[1]
            if parsed[1]=="highshoe":
                print "You smack the wall with your high heeled shoe, all this does is break the heel off.No more beauty pagents for you mister."
                print "Items get: normalshoe, pointyheel"
                inventory.append("pointyheel")
                inventory.append("normalshoe")
                inventory.remove("highshoe")
            if parsed[1]=="sticker" and "pointyheel" and "normalshoe" in inventory:
                print"How smart of you! you attatch the pointy heel onto the toe of the shoe using the sticker. You can now stab stuff with your feet! (by typing 'stab') "
                stab = True
            if parsed [1] == "key" and currentplace == middle:
                print "You open the chest and a massive spider comes out!!! HELP!(It's a boss fight... this will be good -_- )"
                stabspot.append(middle)
                spider = 2
        else:
            print "No can do bucko."
    
    
    if spider == 3:
        print "\nThanks for playing!\n"
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,714
    Rep Power
    480
    Where you have
    if currentplace == southside and kicks != 3:
    should probably use a < comparison:
    if currentplace == southside and kicks < 3:

    It's easy to make your long line output prettier---use the textwrap module.
    Code:
        elif (parsed[0] in ["stab", "kick"]) and stab and (currentplace in stabspots):
            if currentplace == southside and kicks != 3:
                print "You kick the small crack and it becomes larger."
                kicks = kicks + 1  
            if kicks >= 3:
                southside = Place("You have reached the south side of the chifferobe how spookie.The crack on the east side is now just large enough for you to squish through.",[])
                southside.exits=[middle,outside,None,None]
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo