コード例 #1
0
        public async Task <ApiResponse <GameModel> > CreateGame()
        {
            if (User.Identity.IsAuthenticated)
            {
                return(BadRequest("User is already in a game."));
            }

            var game = new Game(
                Guid.NewGuid().ToString().Substring(0, 6).ToUpper(),
                _nameGenerator.GetRandomName(),
                Team.Red);

            await _repository.AddGame(game);

            var player = game.Players.First();

            await SignInAsPlayer(player, game.Code);

            return(Created(game.Code, new GameModel(game, player.Id)));
        }
コード例 #2
0
 public string GetRandomName()
 => _nameGenerator.GetRandomName();