Ah! Never mind! I forgot you could embed classes such as:
class Heroes():
class Lords():
class Phill():
hp = 25
>>> Heroes.Lords.Phill.hp
25
------------------------------------------------------
I am attempting to write an RPG in Python. I am not worrying about the battle system or mapping quite yet, and am more focused on the internal variable handling. My biggest concern is not how to set each variable, but how to format my code to make this as efficient as possible.
Is it better practice to create a class for the heroes and then a function for each hero? Or is a class for the heroes and then a function for "stats" and "attributes" a better way to go, addressing these functions for each hero specifically? For example:
class Hero(heroID, heroClass):
def Stats(heroID)
maxHP = 0
maxMP = 0
atk = 0
res = 0 # res = defense
mres = 0
spd = 0
ski = 0
def Attributes(heroClass)
mountedUnit = 0
flyingUnit = 0
walkOnWater = 0
canUseSword = 0
canUseLance = 0
canUseAxe = 0
canUseBow = 0
canUseLightMagic = 0
canUseDarkMagic = 0
canUseStaves = 0
canUseLockpick = 0
or
class Hero():
def Phill():
heroClass = classDict[0] # Lord class
startLvl = 1
mountedUnit = 0
flyingUnit = 0
walkOnWater = 0
canUseSword = 1
canUseLance = 1
canUseAxe = 0
canUseBow = 0
canUseLightMagic = 0
canUseDarkMagic = 0
canUseStaves = 0
canUseLockpick = 0
def Ork():
heroClass = classDict[1] # Knight class
startLvl = 3
mountedUnit = 1
flyingUnit = 0
walkOnWater = 0
canUseSword = 1
canUseLance = 1
canUseAxe = 0
canUseBow = 0
canUseLightMagic = 0
canUseDarkMagic = 0
canUseStaves = 0
canUseLockpick = 0
If I were to use the class Hero() ... def Stats() ... def Attributes() method, how do I address each variable from inside of a class/function? For example, how do I manipulate maxHP or canUseSword for each hero individually? I'm looking for something along the lines of:
Hero.Stats.maxHP(Phill) = 25
Hero.Stats.atk(Phill) = 15
Hero.Stats.res(Phill) = 10
damage = (Hero.Stats.atk(heroName) * 2) - (Enemy.Stats.res(enemyName) * 1.5)
I am new-ish to Python programming, as I used to be a lot better with the language, but gave it up for a long time. I'm going to use this RPG as a method of relearning the language and sharpening my programming skills in general.
Thanks for your time,
Alex