Too many parameters! HELP!

Started by
9 comments, last by rip-off 11 years, 10 months ago

An example is an objects move() function, this move function checks for collisions, if there is a collision it calls a damage function which might cause the player to die and then call a GameOver() function which resets the game.

The game over function needs to reset alot of variables which i as a (good?) c++ developer is passing to it as parameters, but those parameters come from the damage function which gets them from the move function. So when i call the move function in the main function, it basically needs pointers to all the variables in the game which seems really really silly!

I can't possibly believe this is the way to go, but neither is global variables.
[/quote]
The player does not directly tell the game to end. This unnecessarily couples the player class to the game.

One way to decouple your scenario is to use callbacks. The game hooks into the player's death event, and when the player notifies any listeners that it has died, the game can use this to end itself.

Alternatively, when the game is removing dead objects, it can notice that the object that has died is the player, and react appropriately.

This topic is closed to new replies.

Advertisement