コード例 #1
0
ファイル: GameService.cs プロジェクト: PavelShcherbakov/BJ
        public async Task <GetStateGameResponseView> GetState(string userId)
        {
            var game = await _gameRepository.GetActiveGameAsync(userId);

            var botsPoints = (await _botsPointsRepository.GetPointsByGameIdAsync(game.Id)).ToList();
            var user       = await _userRepository.GetByIdAsync(userId);

            var userSteps = (await _usersStepRepository.GetStepsByGameIdAsync(game.Id)).ToList();

            var response = new GetStateGameResponseView();

            response.GameId = game.Id;

            var bots = new List <BotGetStateGameResponseViewItem>();

            botsPoints.ForEach(
                bp =>
            {
                bots.Add(new BotGetStateGameResponseViewItem()
                {
                    CardsInHand = bp.CardsInHand,
                    Name        = bp.Bot.Name
                });
            }
                );
            response.Bots = bots;

            var userName = user.UserName;
            var cards    = new List <CardGetStateGameResponseViewItem>();

            userSteps.ForEach(
                x => cards.Add(new CardGetStateGameResponseViewItem()
            {
                Rank = (int)x.Rank,
                Suit = (int)x.Suit
            })
                );
            var userGetStatusGameViewItem = new UserGetStateGameResponseView()
            {
                Name  = userName,
                Cards = cards,
                State = new StateGetStateGameResponseView()
                {
                    State         = (int)game.State,
                    StateAsString = game.State.ToString()
                }
            };

            response.User = userGetStatusGameViewItem;

            return(response);
        }
コード例 #2
0
ファイル: HistoryService.cs プロジェクト: PavelShcherbakov/BJ
        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);
        }