Esempio n. 1
0
        public async Task <TakeCardRoundView> TakeCard(long gameId)
        {
            List <GamePlayer> players = await _gamePlayerRepository.GetAllByGameId(gameId);

            await DistributeCards(players, CardValue.OneCardPerPlayer, false);

            CountCardScoreForPlayers(players);
            await _gamePlayerRepository.UpdateMany(players);

            string     roundResult = GameMessage.RoundInProcess;
            GamePlayer human       = players.Where(m => m.Player.Type == PlayerType.Human).First();

            if (human.CardScore >= CardValue.MaxCardScore)
            {
                GamePlayer dealer = players.Where(m => m.Player.Type == PlayerType.Dealer).First();
                await DistributeEndCardsForDealer(dealer);

                roundResult = GetRoundResult(human, dealer);
                Game game = CustomMapper.MapGame(gameId, roundResult);
                await _gameRepository.Update(game);

                await _historyMessageManager.AddMessagesForRound(players, roundResult, gameId);
            }

            TakeCardRoundView view = CustomMapper.MapTakeCardRoundView(players, roundResult);

            return(view);
        }
Esempio n. 2
0
        public async Task <EndRoundView> End(long gameId)
        {
            List <GamePlayer> players = await _gamePlayerRepository.GetAllByGameId(gameId);

            GamePlayer human  = players.Where(m => m.Player.Type == PlayerType.Human).First();
            GamePlayer dealer = players.Where(m => m.Player.Type == PlayerType.Dealer).First();

            await DistributeEndCardsForDealer(dealer);

            string roundResult = GetRoundResult(human, dealer);
            Game   game        = CustomMapper.MapGame(gameId, roundResult);
            await _gameRepository.Update(game);

            await _historyMessageManager.AddMessagesForRound(players, roundResult, gameId);

            EndRoundView view = CustomMapper.MapEndRoundView(dealer, roundResult);

            return(view);
        }