At the moment, I can randomly choose from an enum and assign it to my variable:
(*itL).setDirection(static_cast<LadyDirection>(rand()% NUM_DIRECTIONS));
void Ladybug::setDirection(LadyDirection temp_direction)
{
this->direction = temp_direction;
}
enum LadyDirection
{
North,
East,
South,
West,
NUM_DIRECTIONS
};
What I want to do is make this change to a random enum value, that isn't what it currently is. Eg. If the direction is == North, set it to East, West or South, randomly.
I know I could do this with a few if/elseif statements, but I'd rather know if there's someway to do this nicer.
Thanks.
Aucun commentaire:
Enregistrer un commentaire