[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Text-Based RPG



"Jonah Fishel" <globalparadox@xxxxxxxxxxx> was asking:

> Could I make a Room class that has functions based on different
> variables and then make a separate class for each room like
> AnthroTavern(Room) so I could base it on the rom class and use the
> functions for the room class?

I had a manager once, his motto was "this is software, we can do anything".

So, the answer to "Could I make a class..." is "yes". A good next question
would be "would I want to?", and in this case I think the answer is "no".

You certainly could make a Tavern Room subclass of the Room class, but it
probably makes more sense to make a generic Location class, and then use
data (loaded from text files like I think you're already doing, or loading
from a database, or... any number of other data-driven solutions) to give
it the specific characteristics that you want (Dark Room, Tavern, Cave, In
Front of House, Flood Control Gate #8).

Writing code for each specific location is a lot more work, and probably
going to give you redundant code, and more errors.

This is just one page discussing data driven programming:
http://www.faqs.org/docs/artu/ch09s01.html


-Dave LeCompte