Fw: [Tutor] my newbie program
david
din22@cox.net
Tue Dec 10 23:40:02 2002
----- Original Message -----
From: david <din22@cox.net>
To: Magnus Lycka <magnus@thinkware.se>
Sent: Tuesday, December 10, 2002 10:38 PM
Subject: Re: [Tutor] my newbie program
> hello everyone and thanks for all the food for thought
> concerning global variables. i am still struggling with all
> this though. i was messing with the code below and i
> took the underscores out because i didn't know what
> they were for and i didn't like them. then i noticed that
> when my rooms are instanciated? that they all have their
> own map and dont know about the other rooms. then
> i read about private variables in the tutorial and i don't
> think i get it. also when you raise a KeyError doesn't
> that dump you out of your program? anyway i don't
> want to get my program working at the expense of
> understanding it. tia.
> david
> >
> > class Map:
> > def __init__(self):
> > self.__grid={} # Don't assume global startroom
> > def addRoom(self, room, x, y):
> > if self.__grid.has_key((x,y)):
> > raise KeyError, "Location occupied"
> > self.__grid[(x, y)] = room
> > def getRoom(self, x, y):
> > return self.__grid[(x, y)]
> > def getLocation(self, room):
> > for coord, aRoom in self.__grid.items():
> > if room == aRoom:
> > return coord
> > raise KeyError
> >
> > class Room:
> > def __init__(self, map, x=0, y=0):
> > self.__map = map
> > map.addRoom(self, x, y)
> > def dig(direction):
> > ...
> >
>
>