I have a game with such events as GameOver, GameStart, PlayerWin, etc. I only have one class that is listening on these events, for the purpose of sending these events as TCP json messages to a client (player).
But for every important game function I write, I have to write an event
and then call
if(MyEvent != null)
MyEvent(this, new GameEventArgs("gameover"));
I could as easily avoid writing an event
for each important action and instead include the listener as an instantiated class and simply send messages that way.
private GameListener gameListner = new GameListener();
private void GameOver(){
this.turnTimer.enabled = false;
this.winner = player; //etc
gameListener.GameOver(player);
}
class GameListener{
public void GameOver(Player player){
JSON json = EncodeJson(GAME_OVER, player);
SendClientData(json);
}
}
Is there any reason I should stick to events and delegates?