What's the best way to write this base class?

Chris Kaynor ckaynor at zindagigames.com
Sun Jun 19 21:52:50 EDT 2011


On Jun 18, 2011, at 9:26, John Salerno <johnjsal at gmail.com> wrote:

> Whew, thanks for all the responses! I will think about it carefully
> and decide on a way. I was leaning toward simply assigning the health,
> resource, etc. variables in the __init__ method, like this:
> 
> def __init__(self, name):
>    self.name = name
>    self.health = 50
>    self.resource = 10
> 
> I never did like the idea of using the parameters if I never intended
> to pass them in...just seems wrong.   :)
> 
> The idea of not using a base Character class at all threw me for a
> loop though, so I need to think about that too!

Having a character class (along with possibly player character, non-player character, etc), make sense; however you probably want to make stuff like health, resources, damage, and any other attributes not be handles by any classes or inheritance in order to allow you to make such data-driven (ie, read from a file). Doing so makes the game much more extendable: using classes, you are likely limited to 5 or 'combinations and a few developers (plus, any designers need to know programming).

A basic way to determine between using subclasses over a data driven approach is: is there significantly different back-end behavior or merely attribute differences.

> --
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list