Ejemplo n.º 1
0
        public async Task <ResponseStartGameView> GetStartGameView(long playerId, long sessionId)
        {
            (Player player, Player dealer, IEnumerable <Player> bots) = await _gameManager.GetAllGamePlayers(playerId, sessionId);

            ResponseStartGameView gameView = StartGameViewMapper.GetStartGameView(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 = StartGameViewMapper.GetHandLoadGameViewItem(playerCards, playerScore);
            gameView.Dealer.Hand = StartGameViewMapper.GetHandLoadGameViewItem(dealerCards, dealerScore);

            foreach (var bot in gameView.Bots)
            {
                IEnumerable <Card> botCards = await _gameManager.GetCards(bot.Id, sessionId);

                int botScore = await _gameManager.GetHandScore(bot.Id, sessionId);

                bot.Hand = StartGameViewMapper.GetHandLoadGameViewItem(botCards, botScore);
            }

            return(gameView);
        }
Ejemplo n.º 2
0
        public async Task <ResponseStartGameView> Start(long playerId, int botsNumber)
        {
            if (botsNumber < 0)
            {
                throw new ArgumentException(UserMessages.BotsNumberMustBePositiveMessage);
            }
            ResponseStartGameView gameView = await GiveFirstCards(playerId, botsNumber);

            return(gameView);
        }
Ejemplo n.º 3
0
        public static ResponseStartGameView GetStartGameView(long sessionId, Player dealer, Player player, IEnumerable <Player> bots)
        {
            var responseStartGameView = new ResponseStartGameView
            {
                Player    = GetPlayerStartGameViewItem(player),
                Dealer    = GetDealerStartGameViewItem(dealer),
                Bots      = GetPlayerStartGameViewItems(bots),
                SessionId = sessionId
            };

            return(responseStartGameView);
        }
Ejemplo n.º 4
0
        private async Task <ResponseStartGameView> CreateGameView(long playerId, int botsNumber)
        {
            Player player = await _playerManager.GetPlayerById(playerId);

            GameSession session = await _sessionManager.GetNew();

            IEnumerable <Player> bots = await _playerManager.GetBots(botsNumber);

            Player dealer = await _playerManager.GetDealer();

            ResponseStartGameView gameView = StartGameViewMapper.GetStartGameView(session.Id, dealer, player, bots);

            return(gameView);
        }
Ejemplo n.º 5
0
        public async Task <IHttpActionResult> Start([FromBody] RequestStartGameView request)
        {
            try
            {
                ResponseStartGameView view = await _service.Start(request.PlayerId, request.BotsNumber);

                return(Ok(view));
            }
            catch (Exception exception)
            {
                Log.Error(exception.ToString());
                return(InternalServerError(exception));
            }
        }
Ejemplo n.º 6
0
        private async Task <ResponseStartGameView> GiveFirstCards(long playerId, int botsNumber)
        {
            ResponseStartGameView gameView = await CreateGameView(playerId, botsNumber);

            List <long> playerIds = new List <long>
            {
                playerId,
                gameView.Dealer.Id
            };

            playerIds.AddRange(gameView.Bots.Select(bot => bot.Id));
            await GiveFirstTwoCards(playerIds, gameView.SessionId);

            gameView = await _gameViewManager.GetStartGameView(playerId, gameView.SessionId);

            return(gameView);
        }