Original Post
I have stumbled upon yet another design decision. I have been programming most of my project using OOP practices and methods where I see it most beneficial.
For entities within my game, would it be wise to create a object-driven state machine? What I mean is using objects to represent states.
I guess you can put in the details that''s not here. But basically state changes look like:
Or something similar. This is opposed to having a lot of nested switch statements like:
That could get awfully messy since it''s essentially having as many process subroutines in a single function seperated by case statements.
I''d like some tips on how to go about this, thanks in advance!
class EntityState; //a virtual state class
class Attack: public EntityState
{
public:
void Process();
};
void Attack::Process()
{
//here contains the processing that is to be done for the entity
//including state changes though the actual implementation is not here
}
class SomeEntity
{
public:
void Process();
private:
EntityState State;
}
void SomeEntity::Process()
{
State->Process();
}
State = Action;
void SomeEntity::Process()
{
switch (ActionState)
{
case SE_ATTACK:
break;
case SE_CASTINGSPELL:
break;
}
}