Advertisement
Guest User

Untitled

a guest
Aug 27th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. public class GameService
  2. {
  3.     public void PlayAction(Connection peer, PlayPacket packet)
  4.     {
  5.         GameEngine g = GetGameEngineByPeer(peer)
  6.        
  7.         lock (g.SyncRoot)
  8.         {
  9.             g.Play(packet.Param);
  10.         }
  11.     }
  12.  
  13.     public void PlayHandler(object sender, PlayResultArgs e)
  14.     {
  15.         var g = (GameEngine)sender;
  16.         lock (g.SyncRoot)
  17.         {
  18.             // boradcast to other peers
  19.         }
  20.     }
  21. }
  22.  
  23. public class GameEngine
  24. {
  25.     private readonly object _syncRoot = new Object();
  26.  
  27.     public object SyncRoot { get { return _syncRoot; } }
  28.  
  29.     public void Play(int param)
  30.     {
  31.         // does something really cool
  32.         OnPlayed();
  33.     }
  34.  
  35.     public event EventHandler<PlayResultArgs> Played;
  36.  
  37.     private void OnPlayed()
  38.     {
  39.         if (Played != null) Played(this, new PlayedResultArgs());
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement