Beispiel #1
0
        public async Task <GetCardGameResponseView> GetCard(string userId)
        {
            var game = await _gameRepository.GetActiveGameAsync(userId);

            var usersPoints = await _usersPointsRepository.GetPointsByGameIdAsync(game.Id);

            var botsPoints = (await _botsPointsRepository.GetPointsByGameIdAsync(game.Id)).ToList();

            await RoundCardsDeal(game, usersPoints, botsPoints);

            await _gameRepository.UpdateAsync(game);

            var response = await CreateGetCardGameResponseView(userId, game, botsPoints, usersPoints);

            return(response);
        }
Beispiel #2
0
        public async Task <GetGameInfoHistoryResponseView> GetGameInfo(string userId, GetGameInfoHistoryView model)
        {
            var game = await _gameRepository.GetByIdAsync(model.GameId);

            var response = new GetGameInfoHistoryResponseView();


            response.Steps = new List <StepGetGameInfoHistoryResponseViewItem>(game.CountStep);
            for (int i = 0; i < game.CountStep; i++)
            {
                response.Steps.Add(new StepGetGameInfoHistoryResponseViewItem());
            }

            response.Steps.ForEach(
                x =>
            {
                x.PlayerInfo = new List <PlayerInfoGetGameInfoHistoryResponseViewItem>();
            });

            var userSteps = (await _usersStepRepository.GetStepsByGameIdAsync(model.GameId)).ToList();
            var botSteps  = (await _botsStepRepository.GetStepsByGameIdAsync(model.GameId)).ToList();
            var userName  = (await _userRepository.GetByIdAsync(userId)).UserName;


            userSteps.ForEach(
                x =>
            {
                var pi = new PlayerInfoGetGameInfoHistoryResponseViewItem()
                {
                    Name = userName,
                    Card = new CardGetGameInfoHistoryResponseView()
                    {
                        Suit = new SuitGetGameInfoHistoryResponseView()
                        {
                            Suit         = (int)x.Suit,
                            SuitAsString = x.Suit.ToString()
                        },
                        Rank = new RankGetGameInfoHistoryResponseView()
                        {
                            Rank         = (int)x.Rank,
                            RankAsString = x.Rank.ToString()
                        }
                    }
                };
                response.Steps.ElementAt(x.StepNumder - 1).PlayerInfo.Add(pi);
            });

            botSteps.ForEach(
                x =>
            {
                var pi = new PlayerInfoGetGameInfoHistoryResponseViewItem()
                {
                    Name = x.Bot.Name,
                    Card = new CardGetGameInfoHistoryResponseView()
                    {
                        Suit = new SuitGetGameInfoHistoryResponseView()
                        {
                            Suit         = (int)x.Suit,
                            SuitAsString = x.Suit.ToString()
                        },
                        Rank = new RankGetGameInfoHistoryResponseView()
                        {
                            Rank         = (int)x.Rank,
                            RankAsString = x.Rank.ToString()
                        }
                    }
                };
                response.Steps.ElementAt(x.StepNumder - 1).PlayerInfo.Add(pi);
            });


            response.Summary = new List <PlayersSummaryGetGameInfoHistoryResponseViewItem>();

            var botPoints  = (await _botsPointsRepository.GetPointsByGameIdAsync(model.GameId)).ToList();
            var userPoints = (await _usersPointsRepository.GetPointsByGameIdAsync(model.GameId));

            var winningPoints = Constants.GameSettings.InitionalPoints;

            botPoints.ForEach(
                bp =>
            {
                if (bp.Points > winningPoints && bp.Points <= Constants.GameSettings.WinningNumber)
                {
                    winningPoints = bp.Points;
                }
            });

            if (userPoints.Points > winningPoints && userPoints.Points <= Constants.GameSettings.WinningNumber)
            {
                winningPoints = userPoints.Points;
            }

            response.Summary.Add(new PlayersSummaryGetGameInfoHistoryResponseViewItem()
            {
                Name   = userName,
                Points = userPoints.Points,
                State  = new StateGetGameInfoHistoryResponseView()
                {
                    State         = userPoints.Points == winningPoints ? (int)UserGameStateType.Win : (int)UserGameStateType.Lose,
                    StateAsString = userPoints.Points == winningPoints ? UserGameStateType.Win.ToString() : UserGameStateType.Lose.ToString()
                }
            });

            botPoints.ForEach(
                bp =>
            {
                response.Summary.Add(new PlayersSummaryGetGameInfoHistoryResponseViewItem()
                {
                    Name   = bp.Bot.Name,
                    Points = bp.Points,
                    State  = new StateGetGameInfoHistoryResponseView()
                    {
                        State         = bp.Points == winningPoints ? (int)UserGameStateType.Win : (int)UserGameStateType.Lose,
                        StateAsString = bp.Points == winningPoints ? UserGameStateType.Win.ToString() : UserGameStateType.Lose.ToString()
                    }
                });
            });

            return(response);
        }