public async Task <ResponseStandGameView> GetStandGameView(long playerId, long sessionId) { (Player player, Player dealer, IEnumerable <Player> bots) = await _gameManager.GetAllGamePlayers(playerId, sessionId); ResponseStandGameView gameView = StandGameViewMapper.GetStandGameView(sessionId, dealer, player, bots); IEnumerable <Card> playerCards = await _gameManager.GetCards(player.Id, sessionId); IEnumerable <Card> dealerCards = await _gameManager.GetCards(dealer.Id, sessionId); int playerScore = await _gameManager.GetHandScore(player.Id, sessionId); int dealerScore = await _gameManager.GetHandScore(dealer.Id, sessionId); gameView.Player.Hand = StandGameViewMapper.GetHandStandGameViewItem(playerCards, playerScore); gameView.Dealer.Hand = StandGameViewMapper.GetHandStandGameViewItem(dealerCards, dealerScore); (int playerGameState, string playerGameResult) = _gameResultManager.GetGameStateResult(playerScore, dealerScore); gameView.Player.GameResult.State = playerGameState; gameView.Player.GameResult.Result = playerGameResult; foreach (var bot in gameView.Bots) { IEnumerable <Card> botCards = await _gameManager.GetCards(bot.Id, sessionId); int botScore = await _gameManager.GetHandScore(bot.Id, sessionId); (int botGameState, string botGameResult) = _gameResultManager.GetGameStateResult(botScore, dealerScore); bot.Hand = StandGameViewMapper.GetHandStandGameViewItem(botCards, botScore); bot.GameResult.State = botGameState; bot.GameResult.Result = botGameResult; } return(gameView); }
public static ResponseStandGameView GetStandGameView(long sessionId, Player dealer, Player player, IEnumerable <Player> bots) { var responseStandGameView = new ResponseStandGameView { Player = GetPlayerStandGameViewItem(player), Dealer = GetDealerStandGameViewItem(dealer), Bots = GetPlayerStandGameViewItems(bots), SessionId = sessionId }; return(responseStandGameView); }
public async Task <ResponseStandGameView> Stand(long playerId, long sessionId) { await _historyManager.Create(playerId, UserMessages.ChoseToStandMessage, sessionId); await GiveCardsToBots(sessionId); await GiveCardsToDealer(sessionId); ResponseStandGameView gameView = await _gameViewManager.GetStandGameView(playerId, sessionId); await _sessionManager.Close(sessionId); return(gameView); }
public async Task <IHttpActionResult> Stand([FromBody] RequestStandGameView request) { try { ResponseStandGameView view = await _service.Stand(request.PlayerId, request.SessionId); return(Ok(view)); } catch (Exception exception) { Log.Error(exception.Message); return(InternalServerError(exception)); } }