public async Task <long> CreateGame(long playerId, int amountOfBots)
        {
            var game = new Game();

            game.Id = await _gameRepository.Create(game);

            List <Player> players = await CreatePlayerList(playerId, amountOfBots);

            var gamePlayers = new List <GamePlayer>();

            foreach (Player player in players)
            {
                GamePlayer gamePlayer = CustomMapper.GetGamePlayer(player, game.Id);
                gamePlayers.Add(gamePlayer);
            }

            await _gamePlayerRepository.CreateMany(gamePlayers, ToStringHelper.GetTableName(typeof(GamePlayer)));

            List <Log> logs = LogHelper.GetCreationGameLogs(gamePlayers, game);
            await _logRepository.CreateMany(logs, ToStringHelper.GetTableName(typeof(Log)));

            long gameId = game.Id;

            return(gameId);
        }
Beispiel #2
0
        private async Task DistributeFirstCards(IEnumerable <GamePlayer> gamePlayers)
        {
            List <Card> deck = (await _cardRepository.GetAll()).ToList();

            deck = ShuffleDeck(deck);
            var playerCards = new List <PlayerCard>();

            foreach (GamePlayer gamePlayer in gamePlayers)
            {
                gamePlayer.PlayerCards = new List <PlayerCard>();
                PlayerCard firstCard  = AddCardToPlayer(gamePlayer, deck);
                PlayerCard secondCard = AddCardToPlayer(gamePlayer, deck);
                playerCards.AddRange(gamePlayer.PlayerCards);
            }

            await _playerCardRepository.CreateMany(playerCards, ToStringHelper.GetTableName(typeof(PlayerCard)));
        }
Beispiel #3
0
        public async Task <StartRoundResponseViewModel> StartRound(StartRoundRequestViewModel startRoundRequestViewModel)
        {
            List <GamePlayer> players = (await _gamePlayerRepository.GetAllWithoutCards(startRoundRequestViewModel.GameId)).ToList();

            _gamePlayerProvider.CreateBets(players, startRoundRequestViewModel.Bet);
            await DistributeFirstCards(players);

            _gamePlayerProvider.DefinePayCoefficientsAfterRoundStart(players);
            await _gamePlayerRepository.UpdateMany(players);

            await _gameRepository.UpdateStage(startRoundRequestViewModel.GameId, (int)GameStage.StartRound);

            List <Log> logs = LogHelper.GetStartRoundLogs(players, startRoundRequestViewModel.GameId);
            await _logRepository.CreateMany(logs, ToStringHelper.GetTableName(typeof(Log)));

            StartRoundResponseViewModel startRoundResponseViewModel = GetStartRoundResponse(players);

            return(startRoundResponseViewModel);
        }
Beispiel #4
0
        private async Task <List <PlayerCard> > DistributeSecondCards(IEnumerable <GamePlayer> players, long gameId)
        {
            List <Card> deck = (await _cardRepository.ResumeDeck(gameId)).ToList();

            deck = ShuffleDeck(deck);
            var playerCards = new List <PlayerCard>();

            foreach (GamePlayer gamePlayer in players)
            {
                if (!(gamePlayer.Player.Type == (int)PlayerType.Human))
                {
                    await AddSecondCardsToBot(gamePlayer, deck, playerCards);
                }
            }

            await _playerCardRepository.CreateMany(playerCards, ToStringHelper.GetTableName(typeof(PlayerCard)));

            return(playerCards);
        }
Beispiel #5
0
        public async Task <ContinueRoundResponseViewModel> ContinueRound(ContinueRoundRequestViewModel continueRoundRequestViewModel)
        {
            List <GamePlayer> players = (await _gamePlayerRepository.GetAllWithCards(continueRoundRequestViewModel.GameId)).ToList();

            if (continueRoundRequestViewModel.ContinueRound)
            {
                players.Where(m => m.Player.Type == (int)PlayerType.Human).First().BetPayCoefficient = BetValueHelper.DefaultCoefficient;
            }

            List <PlayerCard> playerCardsInserted = await DistributeSecondCards(players, continueRoundRequestViewModel.GameId);

            _gamePlayerProvider.DefinePayCoefficientsAfterRoundContinue(players);
            await _gamePlayerRepository.UpdateManyAfterContinueRound(players);

            await _gameRepository.UpdateStage(continueRoundRequestViewModel.GameId, (int)GameStage.ContinueRound);

            List <Log> logs = LogHelper.GetContinueRoundLogs(players, playerCardsInserted, continueRoundRequestViewModel.GameId);
            await _logRepository.CreateMany(logs, ToStringHelper.GetTableName(typeof(Log)));

            ContinueRoundResponseViewModel continueRoundResponseViewModel = GetContinueRoundResponse(players);

            return(continueRoundResponseViewModel);
        }