예제 #1
0
        public async Task <NewGameResponse> CreateGameAsync(string playerName, string gameSessionName)
        {
            _logger.LogInformation("Attempting to create a game {GameSessionName} requested by player {playerName}", gameSessionName, playerName);

            var player = new Player
            {
                Name = playerName
            };

            var gameSession = await _gameSessionRepository.AddAsync(new GameSession()
            {
                Name    = gameSessionName,
                Players = new List <Player>()
                {
                    player
                },
                JoinCode = Guid.NewGuid().ToString() // TODO: Generate codes not using Guids
            });

            return(new NewGameResponse()
            {
                PlayerJWT = _playerService.GeneratePlayerJWT(player),
                GameJoinCode = gameSession.JoinCode
            });
        }