Beispiel #1
0
        private async Task <JoinGameResponse> JoinGameAsync(string gameId, Player player)
        {
            try
            {
                GameState gameState = serverState.GetGameState(gameId);
                GameState newState  = gameLogic.AddPlayer(gameState, player);
                serverState.UpdateGameState(newState, addedSecondPlayer: true);
                // Notify opponent
                var notification = new GameNotification
                {
                    NewGameState = newState
                };
                await Clients.Client(newState.Player1.Id).ReceiveGameStateUpdate(notification).ConfigureAwait(false);

                return(new JoinGameResponse
                {
                    State = JoinGameResponseType.SUCCESS,
                    GameState = newState,
                });
            }
            catch (GameNotFoundException)
            {
                return(new JoinGameResponse
                {
                    State = JoinGameResponseType.GAME_NOT_FOUND,
                    GameState = null
                });
            }
        }