[Tutor] my newbie program
alan.gauld@bt.com
alan.gauld@bt.com
Tue Nov 19 13:52:02 2002
> dig(north) would create a new exit to a new room
> with an exit back to the room you dug from.
Something like:
class Rooom:
# as before...
directions = ['north','east',west,'south']
def dig(self, direction):
self.exits[direction] = Room("My new room")
dirindex = directions.index(direction)
newdir = directions[-dirindex+1] # get inverse direction
self.exits[direction].exits[newdir] = self
Note I've changed exits from a list to a dictionary keyed by direction.
I add the new room as the new exit of the current room.
I find the index of the direction in the list
I take the inverse by using the negative index - try it out by hand...
I add the exising room as an exit to the new one...
All untested of course but might form a basis???
Alan g.