game-programming-patterns
game-programming-patterns copied to clipboard
Design question: Is Subclass-sandbox an overcomplicated strategy pattern?
What seems complicated is initialising concrete Superpowers with the necessary resources (playSound(), spawnParticles(), etc) in section "How does the base class get the state that it needs?".
I wonder if the Strategy pattern could be used instead of the new pattern? Let me explain briefly what I mean and perhaps you could elaborate on the similarities and/or differences of both approaches: Say you have an interface Superpower -
class Superpower{
public:
virtual void perform(SuperpowerResources* res) = 0;
};
Any new super power you would create then realises the interface. Following, the SuperpowerResources class is separately initialised, containing the necessary resources the super power implementations need -
class SuperpowerResources{
public:
void move(double x, double y, double z)
{
// Code here...
}
void playSound(SoundId sound, double volume)
{
// Code here...
}
void spawnParticles(ParticleType type, int count)
{
// Code here...
}
};