Exemplo n.º 1
0
        private void OnAddClient(CometAsyncRequestState state, CometEventArgs e)
        {
            if (!IsClientUsed(state.ClientId))
            {
                int lastIdx = Math.Max(_games.Count - 1, 0);
                Game game = _games.Count > lastIdx ? _games[lastIdx] : null;
                if (null == game || (!string.IsNullOrEmpty(game.ClientId1) && !string.IsNullOrEmpty(game.ClientId2)))
                {
                    game = new Game();
                    _games.Add(game);
                }
                
                if (string.IsNullOrEmpty(game.ClientId1))
                {
                    game.ClientId1 = state.ClientId;
                }
                else if (string.IsNullOrEmpty(game.ClientId2))
                {
                    game.ClientId2 = state.ClientId;

                    startGameResponse response = new startGameResponse();
                    response.GameId = game.GameId;
                    response.FirstClientId = (new Random().Next(100)) > 50 ? game.ClientId1 : game.ClientId2;

                    CometClientProcessor.Inst.SendToClient(game.ClientId1, response);
                    CometClientProcessor.Inst.SendToClient(game.ClientId2, response);
                }
            }
        }
Exemplo n.º 2
0
        private void OnStartGame(startGameResponse response)
        {
            //_div.innerHTML += "Start Game ID = " + response.GameId + "<br/>";
            _figure = (response.FirstClientId == this.ClientId) ? EState.x : EState.o;
            //_div.innerHTML += "You are " + _figure + "<br/>";

            _turnClientId = response.FirstClientId;

            RefreshTurn();
        }