[Tutor] Design Question... from a newbie

Liam Clarke cyresse at gmail.com
Wed Oct 20 22:55:23 CEST 2004


Heh self.name is a legitimate website. 


On Thu, 21 Oct 2004 09:31:16 +1300, Liam Clarke <cyresse at gmail.com> wrote:
> That other person would be me....
> 
> ...ah, RPG's... I can create the next text based Morrowind. : )
> 
> But seriously, I can see how (programming) classes would be useful in
> a RPG.  Might have to potter.
> 
> Renee, perhaps it would be easier for your comprehension if your jobs
> and race were just assigned in text i.e.
> 
> class Character
> 
>  def __init__(self,  job ='Fighter', race = 'Human', alignment="Lawful
> Good", level=0, gold=500):
>        self.job=job
>        self.race=race
>        self.alignment=alignment
>        self.level=level
>        self.gold=gold
> 
> (I'd use the name of the character for the object name, but that's
> just me, and it may not be any good for random generation of NPC's.
> For NPC's you could have a list of names, and it randomly picks one
> when creating NPC object. )
> 
> So, Vlad=Character('Mage', 'Elf', 'Neutral','Evil', 4, )
> 
> I only vaguely understand how classes etc work, but I assume you could
> create an inventory object associated with Vlad, which is a list of
> his items, an itemSword object for the basic definitions of swords...,
> skillsVlad to store his skills, expVlad to calculate his experience,
> and watch to see if he gains a level
> 
> (Assuming AD&D type characters.) You can still test later for the text
> values i.e.
> 
> if Vlad.race=='Elf':
>    print "%s says: 'We don't like your kind around here. This is dwarf
> country!' % NPC.name
> elif Vlad.race=='Dwarf':
>    print "%s claps his arm around your shoulder and shouts 'Let us
> drink together, my brother!'" %s NPC.name
> 
> or
> 
> if Vlad.race=='Elf' and NPC.race =='Dwarf":
>      NPC.attack ("We don't take to pointy eared toffs here boy!", Vlad)
> 
> etc. etc. etc.
> 
> But I'd be curious to see how it goes for you. I'd recommend keeping
> it small, and being very specific about what you're going to track,
> perhaps even use an old rule set like the old
> D&D ones. But that's just because I can see any RPG becoming huuuge.
> cf Morrowind.
> 
> Good luck, happy coding, and thanks for pointing me in an OO
> understanding direction.
> 
> Liam
> 
> 
> 
> On Wed, 20 Oct 2004 21:08:11 +0200, nik <my.mailing.lists at noos.fr> wrote:
> > Another person on the list is asking about good examples for using
> > object orientated programming. This could be a good chance to try
> > something like that.
> >
> > A base class could be person (with basic attributes like 'first name'),
> > and then you create derived classes being mage, warrior etc each with
> > attributes appropriate to that type of character. Another base class
> > could be item, with derived classes weapon, armor, food etc, and then
> > derived from that further specifics (ie sword, staff  from the weapon
> > class). This makes it easier when it comes to expanding into new classes
> > (ie if you wanted to add another character type, ie dwarf, you wouldn't
> > have to re-do all the basic attributes that apply to all characters,
> > like health points etc, just the stuff that is unique to a dwarf). Each
> > level in the class heirachy will introduce it's own relevent attributes.
> > Then, when someone decides to be a dwarf, a lot of the attributes will
> > be automatically set just because they're using the dwarf class.
> >
> > That doesn't answer your question though, but it might help look at
> > things a bit differently.
> >
> > nik
> >
> >
> >
> > Rene Lopez wrote:
> >
> > >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.
> > >
> > >
> > >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>


More information about the Tutor mailing list