[Tutor] Instantiating large numbers of objects?
Sat, 02 Feb 2002 18:36:58 -0800
>Thanks to everyone who's helping me out. When I'm famous
>and wealthy, I promise to remember you all! ;)
If you have lots of detailed, specific room info, then
there's no substitute for having this info *somewhere*.
You can have it in the code (it scales if you add to
the code) or you can have it in a file, which your
code reads, and uses to create objects.
Where should these objects live? We've talked about putting
them in a dictionary, where they can be accessed by name.
We've also looked at adding new objects to globals e.g.
by going: globals()['thegreathall']=Room()
A dungeon or castle is a sophisticated data structure
(potentially). Rooms exit to other rooms, so one approach
is to save where the exits go, as attributes of the rooms.
You could have Connection objects and use composition
I suppose, e.g.
self.exit1 = Connection("Hall")
self.exit2 = Connection("DiningRoom")
In this model, rooms are class definitions, not just
instantiations of Rooms. Given the info associated with
each room, this might work better.
Detailed advice is difficult, because what shapes the
design is the overall structure and purpose of the game
or whatever. Just knowing you want "a lot of rooms"
is an insufficient basis for more than a few tips.
So I'll be quiet now.