Skip to content

Instantly share code, notes, and snippets.

@CodingGorilla
Created January 11, 2011 15:00
Show Gist options
  • Save CodingGorilla/774518 to your computer and use it in GitHub Desktop.
Save CodingGorilla/774518 to your computer and use it in GitHub Desktop.
Receives events and passes them along to subscribers
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