Hello,
This is a general programming architecture question.
In a multiplayer game, what is your approach to handle if one of the players has left?
The problem:
* Let's say there is one Player object that represents this player who has left the game.
* Now every game component that referenced this Player object has to set its references to NULL, so the Player object can be either garbage collected.
* These game components may also have to reset their internal state.
Possible approaches:
1. Subscribe all such game components that deal with Player objects class to a "Player Left" event which is broadcasted by the framework.
2. Do not store references to Player objects in any classes, but instead store only a Player ID number. Then the Player object can be received from the framework by the ID, or the framework shall return NULL if the player has already left the game.
3. Any other approach?
So what do you think about 1-3 points?
↧