i am attempting to write a dig function that will create rooms.
i have succeeded only in getting a headache :)
any suggestions on where i am going wrong would
be super helpful.
thanks,
david

world = {}
class Room:
    def __init__(self,name,coords):
        self.contents = []
        self.name = name
        self.coords = coords
        world[tuple(coords)] = self
    def nextdoor(self,direction):
        if direction == 'n':
            nextdoor =  (self.coords[0], self.coords[1] + 1)
            print nextdoor
        elif direction == 's':
            nextdoor =  (self.coords[0], self.coords[1] - 1)
            print nextdoor
        elif direction == 'e':
            nextdoor =  (self.coords[0] +1, self.coords[1])
            print nextdoor
        elif direction == 'w':
            nextdoor =  (self.coords[0] -1, self.coords[1])
            print nextdoor
    def dig(self,direction):
        target = self.nextdoor(direction)
        print target
        if world.has_key(target):
            print 'already a room there'
        else:
            print "someday we'll make a room here"
            world[target]=Room('newroom',target)
room1 = Room('startroom',[0,0])
 
 
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to