Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GameService
- {
- public void PlayAction(Connection peer, PlayPacket packet)
- {
- GameEngine g = GetGameEngineByPeer(peer)
- lock (g.SyncRoot)
- {
- g.Play(packet.Param);
- }
- }
- public void PlayHandler(object sender, PlayResultArgs e)
- {
- var g = (GameEngine)sender;
- lock (g.SyncRoot)
- {
- // boradcast to other peers
- }
- }
- }
- public class GameEngine
- {
- private readonly object _syncRoot = new Object();
- public object SyncRoot { get { return _syncRoot; } }
- public void Play(int param)
- {
- // does something really cool
- OnPlayed();
- }
- public event EventHandler<PlayResultArgs> Played;
- private void OnPlayed()
- {
- if (Played != null) Played(this, new PlayedResultArgs());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement