I recently picked up a copy of Learn Python 3 The Hard Way, but found that editing and revamping other peoples code was a lot easier for me to learn. I've done a couple so far, but am having a really hard time understanding classes.
I decided to make an RPG Game to both help in my understanding, and to give me a goal to push me to keep learning. My end goal is to have a working RPG in Pygame. I want to be able to walk around a map and display global variables such as health, mana, etc.
For now I am focused on creating the main part of my game -- I've found tons and tons of example codes for battling, items, etc, but I wanted to build it from the ground up, and am having trouble with my character creation.
Short term goal -- run the script, and have each characters' stats pop up, along with a prompt on which you want to create (numbers 1-3). Each character has a list of 3 attacks which do different amounts of damage, spend energy + mana, or arrows.
Heres's my current, basic, main page of code, which I really wanted help with.
I plan on having enemy monsters drop arrows, and mana potions, with energy being restored on each fight:
class PlayerClass:
def __init__(self, hp = 100, damage = 0, energy = 100, strength = 0, mana = 0, arrows = 0):
self.hp = int(hp)
self.damage = int(damage)
self.energy = int(energy)
self.strength = int(strength)
self.mana = int(mana)
self.arrows = int(arrows)
pc = PlayerClass()
pcStats = [pc.hp, pc.damage, pc.energy, pc.strength, pc.mana, pc.arrows]
class Swordsman(PlayerClass):
def __init__(self, hp = 100, damage = 50, energy = 100, strength = 100):
self.hp = int(hp)
self.damage = int(damage)
self.energy = int(energy)
self.strength = int(strength)
s = Swordsman()
sStats = [s.hp, s.damage, s.energy, s.strength]
class Mage(PlayerClass):
def __init__(self, hp = 100, damage = 30, energy = 100, mana = 500):
self.hp = int(hp)
self.damage = int(damage)
self.energy = int(energy)
self.mana = int(mana)
m = Mage()
mStats = [m.hp, m.damage, m.energy, m.mana]
class Archer(PlayerClass):
def __init__(self, hp = 100, damage = 30, energy = 100, arrows = 500):
self.hp = int(hp)
self.damage = int(damage)
self.energy = int(energy)
self.arrows = int(arrows)
a = Archer()
aStats = [a.hp, a.damage, a.energy, a.arrows]
Here are the attacks I wanted to add, but didn't really know where to start:
{"1. Slash: "
"2. Chop: "
"3. Hack: "
}
{"1. Fire Blast: "
"2. Shadowball: "
"3. Arcane Presence: "
}
{"1. Long Shot: "
"2. Rapid Fire: "
"3. Arrow Barrage: "
}