Пример #1
0
        public void OnClientConnected(IObjectConnection connection)
        {
            lock (connectionLock)
                if (this.connection != null)
                {
                    var manager = new TicTacToeManager(this.connection, connection);

                    this.connection.AddEventHandler(manager);
                    connection.AddEventHandler(manager);

                    // Between creating the TicTacToeManager and adding it as an eventhandler to each connection
                    // the other connection could disconnect and the other would be stuck in a ghost game
                    // so check if one the connections has disconnected and notify the manager.
                    if (this.connection.IsStopped)
                    {
                        manager.OnDisconnect(this.connection);
                    }

                    if (connection.IsStopped)
                    {
                        manager.OnDisconnect(connection);
                    }

                    this.connection.RemoveEventHandlers(this);
                    connection.RemoveEventHandlers(this);
                    this.connection = null;
                }
                else
                {
                    this.connection = connection;
                }
        }
Пример #2
0
 private void EndGame()
 {
     InformPlayers();
     player1.RemoveEventHandlers(this);
     player2.RemoveEventHandlers(this);
     player1.Stop();
     player2.Stop();
 }