Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    31
    Rep Power
    2
    Originally Posted by jacobace
    oh ok yeah now i see what you mean, tyvm very much for your help and effort sorry if i was a bit annoying.
    also "src = raw_input('> ')" needed to be "src = input('> ')" it threw an error with raw_ at the start
    hey i've got 1 little problem, ok so i have 12 rooms total... and i can move between all those rooms perfectly for now. but i need this to happen
    when your in room 6 you east to 7 (works) but when your in 7 no matter which direction you move (north,south,west,east,up,down) you will always end up in room 12
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    3
    "src = raw_input('> ')" needed to be "src = input('> ')"
    You are using python 3; I'm generally using python 2.7 (though I actually use both).

    For your question, one simplish way would be to give each Room a dictionary of overridden directions. It would default to empty, meaning all directions functioned normally; otherwise it would have keys of directions to override with values of the coordinate location to take the player to.

    Then in the go function, before calculating the next room coordinates, check that the chosen direction is not in the overridden directions dictionary first.

    Give it a shot,
    -Mek
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    31
    Rep Power
    2
    Originally Posted by Mekire
    You are using python 3; I'm generally using python 2.7 (though I actually use both).

    For your question, one simplish way would be to give each Room a dictionary of overridden directions. It would default to empty, meaning all directions functioned normally; otherwise it would have keys of directions to override with values of the coordinate location to take the player to.

    Then in the go function, before calculating the next room coordinates, check that the chosen direction is not in the overridden directions dictionary first.

    Give it a shot,
    -Mek
    oh ok i see what your saying, im not quite sure on how to code it but i have an idea and ill see if it works
  6. #19
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    3
    We used the coordinates for referring to rooms because it was more generic and minimized code; but we could have just as easily given the rooms names and had each room have a complete dictionary of which directions would take you to which rooms. This override dictionary is identical to this idea, except that you only need to set it for rooms that don't behave normally.

    You just need to add this attribute to the Room class and set it accordingly for rooms that you wish to have exceptions; and then make it so your go function checks if any directions are overridden before using the coordinate method.

    -Mek
  8. #20
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,995
    Rep Power
    481
    Probably not Mek's fault if you didn't state which version of python you use.
    Originally Posted by jacobace
    "src = raw_input('> ')" needed to be "src = input('> ')" it threw an error with raw_ at the start
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #21
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    31
    Rep Power
    2
    Originally Posted by b49P23TIvg
    Probably not Mek's fault if you didn't state which version of python you use.
    i never said it was not was i being mean to him, i was simply just correcting him on an innocent mistake, which is on my behalf because i never told him what version i was using
  12. #22
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    3
    No matter. I already new you were using py3; I just didn't bother to update mine before posting it. So i suppose laziness on my part.

    Anyway, have you managed to successfully implement the room that always takes you to the same place yet?

    -Mek
  14. #23
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    31
    Rep Power
    2
    Originally Posted by Mekire
    No matter. I already new you were using py3; I just didn't bother to update mine before posting it. So i suppose laziness on my part.

    Anyway, have you managed to successfully implement the room that always takes you to the same place yet?

    -Mek
    no sorry, i understand your code, thr structure and how it works. ive tried doing it like 3 different ways, and i just cant seem to quite get it
  16. #24
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    3
    This could be improved a lot, but again hopefully it will give you the idea:

    If you go north and then down you will get to a room that takes you back to the start regardless (code is python 3):

    python Code:
    DIRECTIONS = {"north": ( 0, 1, 0),
                  "south": ( 0,-1, 0),
                  "east" : ( 1, 0, 0),
                  "west" : (-1, 0, 0),
                  "up"   : ( 0, 0, 1),
                  "down" : ( 0, 0,-1)}
     
    ALL_DIRECTIONS = list(DIRECTIONS.keys())
     
    #room data and descriptions would be in another file realistically.
    START_ROOM_TEXT = (
    """\nYou open your eyes and find yourself in on of the C Block computer labs ...
    or, rather, the remnants of it. There are certainly no terminals here, just a pile of debris...
    it reminds you of the aftermath of the 1997 Year 12 muck up - the one where they
    set fire to the electricity transformer causing the entire street to be blacked-out
    for three days. As you stand up, you start to wonder how you got here...
    the stench of decay soon changes that thought to one of getting out ...""")
     
    UP_ROOM_TEXT = ("""\nYou are above the start room.  How interesting.""")
     
    NORTH_ROOM_TEXT = """\nNorth of the start room; amazing."""
     
    BACK_TO_START = """\nThis room takes you back to start regardless. Horrifying."""
     
    class Room:
        def __init__(self,descript,dirs=None,override_dirs=None):
            self.descript = descript
     
            if dirs == None:
                self.available_dirs = ALL_DIRECTIONS.copy()
            else:
                self.available_dirs = dirs
     
            if override_dirs == None:
                self.override_dirs = {}
            else:
                self.override_dirs = override_dirs
     
    class Game:
        # Initialises variables
        def __init__(self):
            self.exit = False
            self.map_dict = self.get_maps()
            self.current_loc = [0,0,0]
            self.CurrentMap = self.map_dict[(0,0,0)]
     
            self.commands = {"go"   : self.go,
                             "quit" : self.quit,
                             "look" : self.look}
     
        def get_maps(self):
            maps = {(0,0,0):Room(START_ROOM_TEXT,["up","north"]),
                    (0,0,1):Room(UP_ROOM_TEXT,["down"]),
                    (0,1,0):Room(NORTH_ROOM_TEXT,["south","down"]),
                    (0,1,-1):Room(BACK_TO_START,"You can't see a thing.",{"all"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)})}
            return maps
     
        def look(self,args=None):
            if not args:
                print(self.CurrentMap.descript)
                if not self.CurrentMap.override_dirs:
                    print("\nYou can go {}.".format(self.CurrentMap.available_dirs))
                else:
                    print(self.CurrentMap.available_dirs)
            else:
                #can we look at other stuff?
                print("Should I be able to see a {} from here?".format(args[0]))
     
        def go(self,args):
            direct = args[0] if args else None
            if direct:
                if direct in self.CurrentMap.override_dirs:
                    self.current_loc = list(self.CurrentMap.override_dirs[direct])
                    self.CurrentMap = self.map_dict[tuple(self.current_loc)]
                    print(self.CurrentMap.descript)
                elif direct in DIRECTIONS and "all" in self.CurrentMap.override_dirs:
                    self.current_loc = list(self.CurrentMap.override_dirs["all"])
                    self.CurrentMap = self.map_dict[tuple(self.current_loc)]
                    print(self.CurrentMap.descript)
                elif direct in self.CurrentMap.available_dirs:
                    for i in range(3):
                        self.current_loc[i]+=DIRECTIONS[direct][i]
                    self.CurrentMap = self.map_dict[tuple(self.current_loc)]
                    print(self.CurrentMap.descript)
                else:
                    if direct not in self.CurrentMap.available_dirs:
                        print("You can not go {}".format(direct))
            else:
                print("Where exactly are you going?")
     
        def quit(self,args):
            if not args:
                print("You have given in to despair and collapse on the floor.")
                self.exit = True
            else:
                print("Oh, {}! Why can't I quit you?".format(args[0]))
     
        def process_command(self,command):
            com = command.lower().split()
            if com and com[0] in self.commands:
                self.commands[com[0]](com[1:])
            else:
                print("Huh?")
     
        def run(self):
            self.look()
            while self.exit != True:
                src = input('> ')
                self.process_command(src)
     
    if __name__ == "__main__":
        #runs the game
        game = Game()
        game.run()


    -Mek
    Last edited by Mekire; May 6th, 2013 at 07:47 PM.
  18. #25
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    31
    Rep Power
    2
    Originally Posted by Mekire
    This could be improved a lot, but again hopefully it will give you the idea:

    If you go north and then down you will get to a room that takes you back to the start regardless (code is python 3):

    python Code:
    DIRECTIONS = {"north": ( 0, 1, 0),
                  "south": ( 0,-1, 0),
                  "east" : ( 1, 0, 0),
                  "west" : (-1, 0, 0),
                  "up"   : ( 0, 0, 1),
                  "down" : ( 0, 0,-1)}
     
    ALL_DIRECTIONS = list(DIRECTIONS.keys())
     
    #room data and descriptions would be in another file realistically.
    START_ROOM_TEXT = (
    """\nYou open your eyes and find yourself in on of the C Block computer labs ...
    or, rather, the remnants of it. There are certainly no terminals here, just a pile of debris...
    it reminds you of the aftermath of the 1997 Year 12 muck up - the one where they
    set fire to the electricity transformer causing the entire street to be blacked-out
    for three days. As you stand up, you start to wonder how you got here...
    the stench of decay soon changes that thought to one of getting out ...""")
     
    UP_ROOM_TEXT = ("""\nYou are above the start room.  How interesting.""")
     
    NORTH_ROOM_TEXT = """\nNorth of the start room; amazing."""
     
    BACK_TO_START = """\nThis room takes you back to start regardless. Horrifying."""
     
    class Room:
        def __init__(self,descript,dirs=None,override_dirs=None):
            self.descript = descript
     
            if dirs == None:
                self.available_dirs = ALL_DIRECTIONS.copy()
            else:
                self.available_dirs = dirs
     
            if override_dirs == None:
                self.override_dirs = {}
            else:
                self.override_dirs = override_dirs
     
    class Game:
        # Initialises variables
        def __init__(self):
            self.exit = False
            self.map_dict = self.get_maps()
            self.current_loc = [0,0,0]
            self.CurrentMap = self.map_dict[(0,0,0)]
     
            self.commands = {"go"   : self.go,
                             "quit" : self.quit,
                             "look" : self.look}
     
        def get_maps(self):
            maps = {(0,0,0):Room(START_ROOM_TEXT,["up","north"]),
                    (0,0,1):Room(UP_ROOM_TEXT,["down"]),
                    (0,1,0):Room(NORTH_ROOM_TEXT,["south","down"]),
                    (0,1,-1):Room(BACK_TO_START,"You can't see a thing.",{"all"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)})}
            return maps
     
        def look(self,args=None):
            if not args:
                print(self.CurrentMap.descript)
                if not self.CurrentMap.override_dirs:
                    print("\nYou can go {}.".format(self.CurrentMap.available_dirs))
                else:
                    print(self.CurrentMap.available_dirs)
            else:
                #can we look at other stuff?
                print("Should I be able to see a {} from here?".format(args[0]))
     
        def go(self,args):
            direct = args[0] if args else None
            if direct:
                if direct in self.CurrentMap.override_dirs:
                    self.current_loc = list(self.CurrentMap.override_dirs[direct])
                    self.CurrentMap = self.map_dict[tuple(self.current_loc)]
                    print(self.CurrentMap.descript)
                elif direct in DIRECTIONS and "all" in self.CurrentMap.override_dirs:
                    self.current_loc = list(self.CurrentMap.override_dirs["all"])
                    self.CurrentMap = self.map_dict[tuple(self.current_loc)]
                    print(self.CurrentMap.descript)
                elif direct in self.CurrentMap.available_dirs:
                    for i in range(3):
                        self.current_loc[i]+=DIRECTIONS[direct][i]
                    self.CurrentMap = self.map_dict[tuple(self.current_loc)]
                    print(self.CurrentMap.descript)
                else:
                    if direct not in self.CurrentMap.available_dirs:
                        print("You can not go {}".format(direct))
            else:
                print("Where exactly are you going?")
     
        def quit(self,args):
            if not args:
                print("You have given in to despair and collapse on the floor.")
                self.exit = True
            else:
                print("Oh, {}! Why can't I quit you?".format(args[0]))
     
        def process_command(self,command):
            com = command.lower().split()
            if com and com[0] in self.commands:
                self.commands[com[0]](com[1:])
            else:
                print("Huh?")
     
        def run(self):
            self.look()
            while self.exit != True:
                src = input('> ')
                self.process_command(src)
     
    if __name__ == "__main__":
        #runs the game
        game = Game()
        game.run()


    -Mek
    can you explain to me how that override works please im having a bit of difficulty with that, cause room 12 isnt the only overide i need, theres also a "maze" between 4 rooms, is there a way i can overide like for example
    if current_loc == (1,2,1) and user_input == ("go north"):
    current_loc == (1,2,5) (current_room = 8)
    that was an example
  20. #26
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    3
    python Code:
    #In the following:
     
    def get_maps(self):
        maps = {(0,0,0):Room(START_ROOM_TEXT,["up","north"]),
                (0,0,1):Room(UP_ROOM_TEXT,["down"]),
                (0,1,0):Room(NORTH_ROOM_TEXT,["south","down"]),
                (0,1,-1):Room(BACK_TO_START,None,{"all"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)})}
        return maps
     
    #The line:
    (0,1,-1):Room(BACK_TO_START,None,{"all"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)})}
     
    #creates a room where all exits lead to room (0,0,0).  In the previous code I
    #used the second arg as a cute way to print something for look but this method
    #is probably not practical.
     
    #In the go function I have:
    elif direct in DIRECTIONS and "all" in self.CurrentMap.override_dirs:
        self.current_loc = list(self.CurrentMap.override_dirs["all"])
        self.CurrentMap = self.map_dict[tuple(self.current_loc)]
        print(self.CurrentMap.descript)
     
    #so if the user enters "go" + any valid direction, they will be taken to (0,0,0).
     
    #Instead of overriding all directions I could just override a couple.
    (0,1,-1):Room(BACK_TO_START,["east","west"],{"east"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0),"west"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)})}
     
    #Now if the user enters one of these directions this runs:
    if direct in self.CurrentMap.override_dirs:
        self.current_loc = list(self.CurrentMap.override_dirs[direct])
        self.CurrentMap = self.map_dict[tuple(self.current_loc)]
        print(self.CurrentMap.descript)

    Anyway, I found an error in my previous code so I'll just repost the whole thing with the change we just talked about.
    python Code:
    DIRECTIONS = {"north": ( 0, 1, 0),
                  "south": ( 0,-1, 0),
                  "east" : ( 1, 0, 0),
                  "west" : (-1, 0, 0),
                  "up"   : ( 0, 0, 1),
                  "down" : ( 0, 0,-1)}
     
    ALL_DIRECTIONS = list(DIRECTIONS.keys())
     
    #room data and descriptions would be in another file realistically.
    START_ROOM_TEXT = (
    """\nYou open your eyes and find yourself in on of the C Block computer labs ...
    or, rather, the remnants of it. There are certainly no terminals here, just a pile of debris...
    it reminds you of the aftermath of the 1997 Year 12 muck up - the one where they
    set fire to the electricity transformer causing the entire street to be blacked-out
    for three days. As you stand up, you start to wonder how you got here...
    the stench of decay soon changes that thought to one of getting out ...""")
     
    UP_ROOM_TEXT = ("""\nYou are above the start room.  How interesting.""")
     
    NORTH_ROOM_TEXT = """\nNorth of the start room; amazing."""
     
    BACK_TO_START = """\nThis room takes you back to start regardless. Horrifying."""
     
    class Room:
        def __init__(self,descript,dirs=None,override_dirs=None):
            self.descript = descript
     
            if dirs == None:
                self.available_dirs = ALL_DIRECTIONS[:]
            else:
                self.available_dirs = dirs
     
            if override_dirs == None:
                self.override_dirs = {}
            else:
                self.override_dirs = override_dirs
     
    class Game:
        # Initialises variables
        def __init__(self):
            self.exit = False
            self.map_dict = self.get_maps()
            self.current_loc = [0,0,0]
            self.CurrentMap = self.map_dict[tuple(self.current_loc)]
     
            self.commands = {"go"   : self.go,
                             "quit" : self.quit,
                             "look" : self.look}
     
        def get_maps(self):
            maps = {(0,0,0):Room(START_ROOM_TEXT,["up","north"]),
                    (0,0,1):Room(UP_ROOM_TEXT,["down"]),
                    (0,1,0):Room(NORTH_ROOM_TEXT,["south","down"]),
    ##                (0,1,-1):Room(BACK_TO_START,None,{"all"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)}),
                    (0,1,-1):Room(BACK_TO_START,["east","west"],{"east"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0),"west"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)})}
            return maps
     
        def look(self,args=None):
            if not args:
                print(self.CurrentMap.descript)
                print("\nYou can go {}.".format(self.CurrentMap.available_dirs))
            else:
                #can we look at other stuff?
                print("Should I be able to see a {} from here?".format(args[0]))
     
        def go(self,args):
            def change_it():
                self.CurrentMap = self.map_dict[tuple(self.current_loc)]
                print(self.CurrentMap.descript)
            direct = args[0] if args else None
            if direct:
                if direct in self.CurrentMap.override_dirs:
                    self.current_loc = list(self.CurrentMap.override_dirs[direct])
                    change_it()
                elif direct in DIRECTIONS and "all" in self.CurrentMap.override_dirs:
                    self.current_loc = list(self.CurrentMap.override_dirs["all"])
                    change_it()
                elif direct in self.CurrentMap.available_dirs:
                    for i in range(3):
                        self.current_loc[i]+=DIRECTIONS[direct][i]
                    change_it()
                else:
                    if direct not in self.CurrentMap.available_dirs:
                        print("You can not go {}".format(direct))
            else:
                print("Where exactly are you going?")
     
        def quit(self,args):
            if not args:
                print("You have given in to despair and collapse on the floor.")
                self.exit = True
            else:
                print("Oh, {}! Why can't I quit you?".format(args[0]))
     
        def process_command(self,command):
            com = command.lower().split()
            if com and com[0] in self.commands:
                self.commands[com[0]](com[1:])
            else:
                print("Huh?")
     
        def run(self):
            self.look()
            while self.exit != True:
                src = raw_input('> ')
                self.process_command(src)
     
    if __name__ == "__main__":
        #runs the game
        game = Game()
        game.run()

    -Mek
  22. #27
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    31
    Rep Power
    2
    Originally Posted by Mekire
    python Code:
    #In the following:
     
    def get_maps(self):
        maps = {(0,0,0):Room(START_ROOM_TEXT,["up","north"]),
                (0,0,1):Room(UP_ROOM_TEXT,["down"]),
                (0,1,0):Room(NORTH_ROOM_TEXT,["south","down"]),
                (0,1,-1):Room(BACK_TO_START,None,{"all"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)})}
        return maps
     
    #The line:
    (0,1,-1):Room(BACK_TO_START,None,{"all"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)})}
     
    #creates a room where all exits lead to room (0,0,0).  In the previous code I
    #used the second arg as a cute way to print something for look but this method
    #is probably not practical.
     
    #In the go function I have:
    elif direct in DIRECTIONS and "all" in self.CurrentMap.override_dirs:
        self.current_loc = list(self.CurrentMap.override_dirs["all"])
        self.CurrentMap = self.map_dict[tuple(self.current_loc)]
        print(self.CurrentMap.descript)
     
    #so if the user enters "go" + any valid direction, they will be taken to (0,0,0).
     
    #Instead of overriding all directions I could just override a couple.
    (0,1,-1):Room(BACK_TO_START,["east","west"],{"east"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0),"west"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)})}
     
    #Now if the user enters one of these directions this runs:
    if direct in self.CurrentMap.override_dirs:
        self.current_loc = list(self.CurrentMap.override_dirs[direct])
        self.CurrentMap = self.map_dict[tuple(self.current_loc)]
        print(self.CurrentMap.descript)

    Anyway, I found an error in my previous code so I'll just repost the whole thing with the change we just talked about.
    python Code:
    DIRECTIONS = {"north": ( 0, 1, 0),
                  "south": ( 0,-1, 0),
                  "east" : ( 1, 0, 0),
                  "west" : (-1, 0, 0),
                  "up"   : ( 0, 0, 1),
                  "down" : ( 0, 0,-1)}
     
    ALL_DIRECTIONS = list(DIRECTIONS.keys())
     
    #room data and descriptions would be in another file realistically.
    START_ROOM_TEXT = (
    """\nYou open your eyes and find yourself in on of the C Block computer labs ...
    or, rather, the remnants of it. There are certainly no terminals here, just a pile of debris...
    it reminds you of the aftermath of the 1997 Year 12 muck up - the one where they
    set fire to the electricity transformer causing the entire street to be blacked-out
    for three days. As you stand up, you start to wonder how you got here...
    the stench of decay soon changes that thought to one of getting out ...""")
     
    UP_ROOM_TEXT = ("""\nYou are above the start room.  How interesting.""")
     
    NORTH_ROOM_TEXT = """\nNorth of the start room; amazing."""
     
    BACK_TO_START = """\nThis room takes you back to start regardless. Horrifying."""
     
    class Room:
        def __init__(self,descript,dirs=None,override_dirs=None):
            self.descript = descript
     
            if dirs == None:
                self.available_dirs = ALL_DIRECTIONS[:]
            else:
                self.available_dirs = dirs
     
            if override_dirs == None:
                self.override_dirs = {}
            else:
                self.override_dirs = override_dirs
     
    class Game:
        # Initialises variables
        def __init__(self):
            self.exit = False
            self.map_dict = self.get_maps()
            self.current_loc = [0,0,0]
            self.CurrentMap = self.map_dict[tuple(self.current_loc)]
     
            self.commands = {"go"   : self.go,
                             "quit" : self.quit,
                             "look" : self.look}
     
        def get_maps(self):
            maps = {(0,0,0):Room(START_ROOM_TEXT,["up","north"]),
                    (0,0,1):Room(UP_ROOM_TEXT,["down"]),
                    (0,1,0):Room(NORTH_ROOM_TEXT,["south","down"]),
    ##                (0,1,-1):Room(BACK_TO_START,None,{"all"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)}),
                    (0,1,-1):Room(BACK_TO_START,["east","west"],{"east"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0),"west"<img src="http://images.devshed.com/fds/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />0,0,0)})}
            return maps
     
        def look(self,args=None):
            if not args:
                print(self.CurrentMap.descript)
                print("\nYou can go {}.".format(self.CurrentMap.available_dirs))
            else:
                #can we look at other stuff?
                print("Should I be able to see a {} from here?".format(args[0]))
     
        def go(self,args):
            def change_it():
                self.CurrentMap = self.map_dict[tuple(self.current_loc)]
                print(self.CurrentMap.descript)
            direct = args[0] if args else None
            if direct:
                if direct in self.CurrentMap.override_dirs:
                    self.current_loc = list(self.CurrentMap.override_dirs[direct])
                    change_it()
                elif direct in DIRECTIONS and "all" in self.CurrentMap.override_dirs:
                    self.current_loc = list(self.CurrentMap.override_dirs["all"])
                    change_it()
                elif direct in self.CurrentMap.available_dirs:
                    for i in range(3):
                        self.current_loc[i]+=DIRECTIONS[direct][i]
                    change_it()
                else:
                    if direct not in self.CurrentMap.available_dirs:
                        print("You can not go {}".format(direct))
            else:
                print("Where exactly are you going?")
     
        def quit(self,args):
            if not args:
                print("You have given in to despair and collapse on the floor.")
                self.exit = True
            else:
                print("Oh, {}! Why can't I quit you?".format(args[0]))
     
        def process_command(self,command):
            com = command.lower().split()
            if com and com[0] in self.commands:
                self.commands[com[0]](com[1:])
            else:
                print("Huh?")
     
        def run(self):
            self.look()
            while self.exit != True:
                src = raw_input('> ')
                self.process_command(src)
     
    if __name__ == "__main__":
        #runs the game
        game = Game()
        game.run()

    -Mek
    thankyou soo much for your help, i have it all working and i do understand it now thankyou. is there any way i can leave feedback or anything or a way to say thank you?

    Comments on this post

    • Mekire agrees : There is a scale icon on the topleft. Anyway, why not post your program? :P
  24. #28
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    31
    Rep Power
    2
    i keep getting an error on the website when i try and post the code.

    You have included too many images in your signature or in your previous post. Please go back and correct the problem and then continue again.

    Images include use of smilies, the vB code [img] tag and HTML <img> tags. The use of these is all subject to them being enabled by the administrator.
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo