Ejemplo n.º 1
0
        public void PlayOneGame(int nbPlayers)
        {
            DealingRules   dealingRules   = new DealingRules();
            BettingService bettingService = new BettingService();
            PlayerService  playerService  = new PlayerService();
            List <Player>  players        = playerService.CreatePlayers(Musketeers().Take(nbPlayers)).ToList();
            DealingService dealingService = new DealingService(false, players);
            RoundService   roundService   = new RoundService(false, players);

            Player dealer = players.First();

            dealer.Dealer = true;
            dealingService.DealsAllCardsFromDeck();

            Assert.That(dealingService.NbPlayers(), Is.EqualTo(nbPlayers));
            Assert.That(dealingService.CountAside(), Is.EqualTo(dealingRules.AsideMaxCards(nbPlayers)));
            Assert.NotNull(dealingService.GetDealer());
            Assert.Zero(dealingService.GetRoundNumber());
            Assert.That(dealingService.DealtAsideIsCorrect(), Is.True);

            foreach (Player player in players)
            {
                Assert.That(player.Hand.Count == players.First().Hand.Count);
                Assert.That(player.Contract.ToString(), Is.EqualTo("pass"));
            }

            bettingService.GatherBets(players);
            bettingService.AuctionIsWon(dealingService);
            Player attacker = bettingService.GetWinningBet().Key;

            playerService.MakeAside(attacker, dealingService.NbCardsInAside());

            // Put this in dealing service ?
            // Game is ready to start when:
            Assert.That(attacker.Hand.Count, Is.EqualTo(players.First(x => x.Attacker is false).Hand.Count));
            Assert.That(attacker.WonHands.Count, Is.EqualTo(dealingRules.AsideMaxCards(nbPlayers)));
            Assert.Zero(dealingService.GetRoundNumber());

            while (dealer.Hand.Count > 0)
            {
                var round = roundService.PlayRound();
            }

            Assert.Zero(players.Select(x => x.Hand.Count).Sum());
            Assert.That(players.Select(x => x.WonHands.Count).Sum(), Is.EqualTo(DealingRules.MaxCardsInDeck));
            Assert.That(players.Select(x => x.WonHands.Cast <Card>().Score()).Sum(), Is.EqualTo(CardCountingRules.MaxScore));
        }