Beispiel #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);
        }
Beispiel #2
0
        public async Task <IHttpActionResult> Start(RequestStartRoundView requestView)
        {
            try
            {
                ResponseStartRoundView responseView = await _roundService.Start(requestView);

                return(Ok(responseView));
            }
            catch (Exception exception)
            {
                string message = exception.ToString();
                _logger.Error(message);
                return(BadRequest(GameMessage.GameProcessingError));
            }
        }
Beispiel #3
0
        public void StartTest()
        {
            _mockGameRepository        = new Mock <IGameRepository>(MockBehavior.Strict);
            _mockGamePlayerRepository  = new Mock <IGamePlayerRepository>(MockBehavior.Strict);
            _mockPlayerCardRepository  = new Mock <IPlayerCardRepository>(MockBehavior.Strict);
            _mockCardRepository        = new Mock <ICardRepository>(MockBehavior.Strict);
            _mockHistoryMessageManager = new Mock <IHistoryMessageManager>(MockBehavior.Strict);

            var requestView = new RequestStartRoundView()
            {
                GameId = 9, IsNewRound = true
            };
            var gamePlayers = new List <GamePlayer>()
            {
                new GamePlayer()
                {
                    Player = new Player()
                    {
                        Type = PlayerType.Dealer
                    },
                    CardScore = 10
                },
                new GamePlayer()
                {
                    Player = new Player()
                    {
                        Type = PlayerType.Human
                    },
                    CardScore = 10
                }
            };
            var game = new Game()
            {
                RoundResult = ""
            };
            int cardAmount = 4;
            var cards      = new List <Card>()
            {
                new Card()
                {
                    Worth = 9
                },
                new Card()
                {
                    Worth = 11
                },
                new Card()
                {
                    Worth = 4
                },
                new Card()
                {
                    Worth = 10
                }
            };
            var playerCards = new List <PlayerCard>();

            int createMany = 0;

            _mockGamePlayerRepository.Setup(p => p.GetAllByGameId(requestView.GameId)).Returns(Task.FromResult(gamePlayers));
            _mockGameRepository.Setup(p => p.Get(requestView.GameId)).Returns(Task.FromResult(game));
            _mockPlayerCardRepository.Setup(p => p.CreateMany(playerCards)).Returns(Task.FromResult(createMany));
            _mockCardRepository.Setup(p => p.GetSpecifiedAmount(cardAmount)).Returns(Task.FromResult(cards));

            _roundService = new RoundService
                            (
                null,
                _mockGameRepository.Object,
                _mockGamePlayerRepository.Object,
                _mockPlayerCardRepository.Object,
                _mockCardRepository.Object,
                _mockHistoryMessageManager.Object
                            );
            ResponseStartRoundView result = _roundService.Start(requestView).Result;

            result.RoundResult = "";
            Assert.That(result.RoundResult, Is.EqualTo(""));

            //_mockGameRepository.VerifyAll();
            //_mockGamePlayerRepository.VerifyAll();
            //_mockPlayerCardRepository.VerifyAll();
            //_mockCardRepository.VerifyAll();
            //_mockHistoryMessageManager.VerifyAll();
        }