[Tutor] (no subject)

Alan Gauld alan.gauld at freenet.co.uk
Sun Dec 4 18:24:08 CET 2005


> then i run my program and create one room. there should now be two rooms.
> when i look at rooms i have three rooms! where did this other room come 
> from?

Dunno but have uyou tried asking it about itself using the debugger?
Call the description methjod or look at the coordinates...

One wee observation:

rooms = []
class Room:
    def __init__(self,coords):
        self.contents = []
        self.description = ''
        self.coords = coords
        world[tuple(coords)] = self
        rooms.append(self)
        self.exits = {}

I'd either make rooms a class variable which can be accessed
from outside the class with Room.rooms or I'd make the append
operation a responsibility of the calling client. Otherwise every
time you try to use the Room class in another program you will
need to create a rooms global variable.

Since the purpose of rooms is to keep a register of all the rooms in
existence I'd argue it should be a class variable. Just a matter of style
it doesn't really affect the operation here. And certainly doesn't fix
your extra room problem!

Alan G. 



More information about the Tutor mailing list