Пример #1
0
        private async Task CardsDeal(Game game, UsersPoints usersPoints, List <Bot> bots, List <BotsPoints> botsPointsList, bool userPlaying = true)
        {
            game.CountStep += 1;

            var numOfCards = bots.Count;

            if (userPlaying)
            {
                numOfCards += Constants.GameSettings.NumOfUserInGame;
            }

            int countCardInDeck = await _deckRepository.GetCountCardsAsync(usersPoints.GameId);

            while (countCardInDeck < numOfCards)
            {
                await AddDeckAsync(usersPoints.GameId);

                countCardInDeck = await _deckRepository.GetCountCardsAsync(usersPoints.GameId);
            }

            List <Card> takenСards = (await _deckRepository.GetRandomCardsByGameIdAsync(usersPoints.GameId, numOfCards)).ToList();


            var usersSteps = new List <UsersStep>();

            if (userPlaying)
            {
                var us = await UserGetCardAsync(game, takenСards, usersPoints, game.CountStep, --numOfCards);

                usersSteps.Add(us);
            }

            var botsSteps = new List <BotsStep>();
            var modifiedBotsPointsList = new List <BotsPoints>();

            bots.ForEach(
                bot =>
            {
                var botsPoints = botsPointsList.Where(x => x.BotId == bot.Id).FirstOrDefault();

                var botInfo = BotGetCard(takenСards, botsPoints, game.CountStep, --numOfCards);

                botsSteps.Add(botInfo.botsStep);
                modifiedBotsPointsList.Add(botInfo.botsPoints);
            }
                );

            await _botsPointsRepository.UpdateRangeAsync(modifiedBotsPointsList);

            await _usersStepRepository.AddRangeAsync(usersSteps);

            await _botsStepRepository.AddRangeAsync(botsSteps);

            await _deckRepository.RemoveRangeAsync(takenСards);
        }