[Tutor] Design Question... from a newbie
Rene Lopez
RenX99 at gmail.com
Wed Oct 20 20:10:11 CEST 2004
For the last couple weeks I have been teaching myself python and
trying to get a better grasp in programming in general. I'm beginning
to realize that there is more to it then learning a programming
language. I may know how a lot of English words, and how to write a
sentence but I won't be able to write a novel right a way... the same
goes with programming I suppose.
I'm trying to write a small RPG game similar to D&D or whatever. So
I'm trying to figure out how to best keep track of a character and all
of the attributes/variables for that character. I think the key to
this is going to be using a class to create a customer data type, but
I'm not sure if there is a better way. For example I'm using
something like this:
class Character:
def __init__(self, name=' ', job = 1, race = 1):
self.name = name
# assign job
if job == 1:
self.job = job
self.jobdesc = "Fighter"
elif job == 2:
self.job = class
self.job = "Mage"
# assign race
if race == 1:
self.race = race
self.racedesc = "Human"
if race == 2:
self.race = race
self.racedesc = "Elf"
player = Character(name= 'Bob', job=2, race=2)
Would it make more sense to have the class just handle the attributes
and do all of the assignment via a separate function? The example I
gave is very simple.. I imagine as the character information gets more
in depth the list of attributes will grow and grow...so I'm concerned
that it might start to get confusing. What do you gurus think?
PS: I apologize for any programming errors I made...as made the code
up as i went.. and didn't test it... but i figured you'd get the idea.
--
Rene
More information about the Tutor
mailing list