예제 #1
0
        public async Task <IHttpActionResult> StartRound(StartRoundRequestViewModel startRoundRequestViewModel)
        {
            try
            {
                if (startRoundRequestViewModel == null)
                {
                    return(BadRequest(GameMessageHelper.ReceivedDataError));
                }

                string message = await _gameService.ValidateBet(startRoundRequestViewModel.Bet, startRoundRequestViewModel.GamePlayerId);

                if (string.IsNullOrEmpty(message))
                {
                    StartRoundResponseViewModel startRoundResponseViewModel = await _gameService.StartRound(startRoundRequestViewModel);

                    return(Ok(new { Message = message, Data = startRoundResponseViewModel }));
                }

                return(Ok(new { Message = message }));
            }
            catch (Exception ex)
            {
                string message = $"{ex.Source}|{ex.TargetSite}|{ex.StackTrace}|{ex.Message}";
                _logger.Error(message);
                return(BadRequest(GameMessageHelper.GameError));
            }
        }
예제 #2
0
        public async Task <StartRoundResponseViewModel> ResumeAfterStartRound(long gameId)
        {
            List <GamePlayer>           players = (await _gamePlayerRepository.GetAllWithCards(gameId)).ToList();
            StartRoundResponseViewModel startRoundResponseViewModel = GetStartRoundResponse(players);

            return(startRoundResponseViewModel);
        }
예제 #3
0
        public async Task <IHttpActionResult> ResumeAfterStartRound(long gameId)
        {
            try
            {
                StartRoundResponseViewModel startRoundResponseViewModel = await _gameService.ResumeAfterStartRound(gameId);

                return(Ok(startRoundResponseViewModel));
            }
            catch (Exception ex)
            {
                string message = $"{ex.Source}|{ex.TargetSite}|{ex.StackTrace}|{ex.Message}";
                _logger.Error(message);
                return(BadRequest(GameMessageHelper.GameError));
            }
        }
예제 #4
0
        public async Task <StartRoundResponseViewModel> StartRound(StartRoundRequestViewModel startRoundRequestViewModel)
        {
            List <GamePlayer> players = (await _gamePlayerRepository.GetAllWithoutCards(startRoundRequestViewModel.GameId)).ToList();

            _gamePlayerProvider.CreateBets(players, startRoundRequestViewModel.Bet);
            await DistributeFirstCards(players);

            _gamePlayerProvider.DefinePayCoefficientsAfterRoundStart(players);
            await _gamePlayerRepository.UpdateMany(players);

            await _gameRepository.UpdateStage(startRoundRequestViewModel.GameId, (int)GameStage.StartRound);

            List <Log> logs = LogHelper.GetStartRoundLogs(players, startRoundRequestViewModel.GameId);
            await _logRepository.CreateMany(logs, ToStringHelper.GetTableName(typeof(Log)));

            StartRoundResponseViewModel startRoundResponseViewModel = GetStartRoundResponse(players);

            return(startRoundResponseViewModel);
        }
예제 #5
0
        public static StartRoundResponseViewModel GetStartRoundResponseViewModel(List <GamePlayer> players, long gameId, bool canTakeCard, bool isBlackJackChoice)
        {
            GamePlayer human  = players.Where(m => m.Player.Type == (int)PlayerType.Human).First();
            GamePlayer dealer = players.Where(m => m.Player.Type == (int)PlayerType.Dealer).First();

            players.Remove(human);
            players.Remove(dealer);

            var startRoundResponseViewModel = new StartRoundResponseViewModel();

            startRoundResponseViewModel.Dealer            = Mapper.Map <GamePlayer, GamePlayerItem>(dealer);
            startRoundResponseViewModel.Dealer.RoundScore = GameValueHelper.Zero;
            startRoundResponseViewModel.Dealer.Cards.Clear();
            startRoundResponseViewModel.Dealer.Cards.Add(ToStringHelper.GetCardName(dealer.PlayerCards[0].Card));
            startRoundResponseViewModel.Human           = Mapper.Map <GamePlayer, GamePlayerItem>(human);
            startRoundResponseViewModel.Bots            = Mapper.Map <IEnumerable <GamePlayer>, List <GamePlayerItem> >(players);
            startRoundResponseViewModel.CanTakeCard     = canTakeCard;
            startRoundResponseViewModel.BlackJackChoice = isBlackJackChoice;
            startRoundResponseViewModel.Id = gameId;
            return(startRoundResponseViewModel);
        }
예제 #6
0
        private StartRoundResponseViewModel GetStartRoundResponse(List <GamePlayer> players)
        {
            GamePlayer human = players.Where(m => m.Player.Type == (int)PlayerType.Human).First();

            bool canTakeCard = true;

            if (human.RoundScore >= CardValueHelper.BlackJackScore)
            {
                canTakeCard = false;
            }

            bool blackJackChoice = false;

            if (human.BetPayCoefficient == BetValueHelper.WinCoefficient)
            {
                blackJackChoice = true;
            }

            StartRoundResponseViewModel startRoundResponseViewModel =
                CustomMapper.GetStartRoundResponseViewModel(players, human.GameId, canTakeCard, blackJackChoice);

            return(startRoundResponseViewModel);
        }