示例#1
0
        public async Task <StartGameResponseView> StartGame(string userId, StartGameView model)
        {
            var game = new Game()
            {
                UserId          = userId,
                State           = UserGameStateType.InGame,
                NumberOfPlayers = model.NumberOfBots + 1
            };
            await _gameRepository.CreateAsync(game);

            var usersPoints = new UsersPoints()
            {
                UserId = userId,
                GameId = game.Id,
                Points = Constants.GameSettings.InitionalPoints
            };
            await _usersPointsRepository.CreateAsync(usersPoints);

            var bots = (await _botRepository.GetRandomBotsAsync(model.NumberOfBots)).ToList();

            var botsPoints = bots.Select(x => new BotsPoints()
            {
                BotId       = x.Id,
                GameId      = game.Id,
                Points      = Constants.GameSettings.InitionalPoints,
                CardsInHand = Constants.GameSettings.InitialCardsInHand
            })
                             .ToList();
            await _botsPointsRepository.AddRangeAsync(botsPoints);

            await InitialCardsDeal(game, usersPoints, bots, botsPoints);

            await _gameRepository.UpdateAsync(game);

            var response = new StartGameResponseView()
            {
                GameId = game.Id,
                State  = (int)game.State
            };

            return(response);
        }