コード例 #1
0
        public async Task <ResponseStartRoundView> Start(RequestStartRoundView requestView)
        {
            List <GamePlayer> players = await _gamePlayerRepository.GetAllByGameId(requestView.GameId);

            Game game = await _gameRepository.Get(requestView.GameId);

            if (requestView.IsNewRound)
            {
                await RemoveCards(players, game.Id);
                await DistributeCards(players, CardValue.TwoCardsPerPlayer);

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

            game.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);

                game.RoundResult = GetRoundResult(human, dealer);
                await _historyMessageManager.AddMessagesForRound(players, game.RoundResult, game.Id);
            }

            await _gameRepository.Update(game);

            ResponseStartRoundView responseView = CustomMapper.MapResponseStartRoundView(players, game.RoundResult);

            return(responseView);
        }