Hello all,
For a text RPG would it be more efficient to make a class for all spells then link the spells to the job class.. Or to just have the spell function inside the job class itself.
Thanks in advance.
//quick example
class Spells {
public:
};
class MeleeSpells : Spells {
public:
};
// Or..
class Jobs {
public:
};
class Warrior : Job {
public:
//spells and their functions.
Well, in my opinion it would be easier to... well, not quite the former. It's known as the factory build pattern, and basically allows you to toss a basic descriptor of the class (e.g. the type of spell) and get as a result the class specific to that batch of spells. Since the factory returns a pointer of the base class, you don't have to be as specific- the actual character would only have to have an object of a pointer to class spell, not any of the derivations.
I came up with this. Wondering if this is the way to go. Could I just point Firebolts->damage when I need to use it in the function to actually "hurt" the target?
Yep. That is exactly how it would work. If need-be, you could even pass to the function damage the stats of who is being targeted and who is using it, allowing for even more versatility.
Well, the mage class would include an object of class spell. Give that object any name you want, and then just use the arrow operand with that object's name in, say, an attack command.
No, no. You'd make it as if it were a variable within in the class. So you'd have the list of variables, followed by an object that points to an object of type spell.