Created
January 11, 2011 15:00
-
-
Save CodingGorilla/774518 to your computer and use it in GitHub Desktop.
Receives events and passes them along to subscribers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class EventAggregator | |
{ | |
public static readonly EventAgregator Instance = new EventAggregator(); | |
private EventAggregator | |
{ | |
} | |
public event EventHandler PlayerDied; | |
public void OnPlayerDied(Player player) | |
{ | |
if(PlayerDied != null) | |
PlayerDied(player, EventArgs.Empty); | |
} | |
} | |
public class Game | |
{ | |
public void SendPlayerDiedEvent(Player player) | |
{ | |
EventAggregator.Instance.OnPlayerDied(player); | |
} | |
} | |
public class player_objects : IDisposable | |
{ | |
plublic player_objects() | |
{ | |
EventAggregator.Instance.PlayerDied += HandlePlayerDied; | |
} | |
public void Dispose() | |
{ | |
EventAggregator.Instance.PlayerDied -= HandlePlayerDied; | |
} | |
public void HandlePlayerDied(object sender, EventArgs e) | |
{ | |
/* Do something with here */ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment