Ejemplo n.º 1
0
        public void Can_find_winner_When_battle_happened_recursively_and_in_the_end_all_players_have_no_more_cards_except_for_the_winner()
        {
            var game = GameBuilder.BuildGame(new List <List <Card> >
            {
                new List <Card> {
                    s2, d3, d4
                },
                new List <Card> {
                    s3, d2, c5
                },
                new List <Card> {
                    s13, s14, c2
                }
            }, PlayersBuilder.BuildPlayers(3, new CardsShufflerForTest()));


            var gameOver = game.Play();
            var players  = game.Players;
            var player1  = players[0];
            var player2  = players[1];
            var player3  = players[2];

            Check.That(game.TableViewsHistory).HasSize(8);
            Check.That(game.TableViewsHistory[0]).IsEquivalentTo(d4.FaceUp(player1), c5.FaceUp(player2), c2.FaceUp(player3));
            Check.That(game.TableViewsHistory[1]).IsEquivalentTo(d3.FaceUp(player1), d2.FaceUp(player2), s14.FaceUp(player3));
            Check.That(game.TableViewsHistory[2]).IsEquivalentTo(s2.FaceUp(player1), s3.FaceUp(player2), s13.FaceUp(player3));
            Check.That(game.TableViewsHistory[3]).IsEquivalentTo(c5.FaceUp(player2), s14.FaceUp(player3));
            Check.That(game.TableViewsHistory[4]).IsEquivalentTo(d4.FaceUp(player2), d3.FaceUp(player3));
            Check.That(game.TableViewsHistory[5]).IsEquivalentTo(c2.FaceUp(player2), d2.FaceUp(player3));
            Check.That(game.TableViewsHistory[6]).IsEquivalentTo(d4.FaceDown(player2), s13.FaceDown(player3));
            Check.That(game.TableViewsHistory[7]).IsEquivalentTo(s3.FaceUp(player2), d3.FaceUp(player3));

            Check.That(gameOver).IsInstanceOf <HasWinner>();
            var winner = ((HasWinner)gameOver).Winner;

            Check.That(winner).IsEqualTo(player3);
            Check.That(winner.CardStack.Size).IsEqualTo(3);

            Check.That(player1.CardStack).HasSize(0);
            Check.That(player2.CardStack).HasSize(0);
            Check.That(player3.CardStack).HasSize(3);
            Check.That(player3.CardStack).IsEquivalentTo(c5, s14, s2);

            Check.That(game.DroppedCards.Count).IsEqualTo(6);
        }
Ejemplo n.º 2
0
        public void Should_have_correct_number_of_won_cards_and_dropped_cards()
        {
            var game = GameBuilder.BuildGame(new List <List <Card> >
            {
                new List <Card> {
                    s13, s13, d2, c4, d6, s3
                },
                new List <Card> {
                    s6, s5, h9, h4, d7, h3
                },
                new List <Card> {
                    s7, d5, d14, d4, s12, d3
                },
                new List <Card> {
                    s2, d8, h7, s11, s8, c3
                }
            }, PlayersBuilder.BuildPlayers(4, new CardsShufflerForTest()));

            var gameOver  = game.Play();
            var hasWinner = (HasWinner)gameOver;

            Check.That(game.DroppedCards.Count + hasWinner.Winner.CardStack.Size).IsEqualTo(6 * 4);
        }
Ejemplo n.º 3
0
        public void Should_continue_When_a_player_has_no_more_card_after_a_battle_but_not_all_players2()
        {
            var game = GameBuilder.BuildGame(new List <List <Card> >
            {
                new List <Card> {
                    h5, d6, s7
                },
                new List <Card> {
                    s6, s8, h7
                },
                new List <Card> {
                    h4, s3, d2
                }
            }, PlayersBuilder.BuildPlayers(3, new CardsShufflerForTest()));
            var gameOver = game.Play();

            var player0 = game.Players[0];
            var player1 = game.Players[1];
            var player2 = game.Players[2];

            var history = game.TableViewsHistory;

            Check.That(history).HasSize(5);
            Check.That(history[0]).IsEquivalentTo(s7.FaceUp(player0), h7.FaceUp(player1), d2.FaceUp(player2));
            Check.That(history[1]).IsEquivalentTo(d6.FaceDown(player0), s8.FaceDown(player1));
            Check.That(history[2]).IsEquivalentTo(h5.FaceUp(player0), s6.FaceUp(player1));
            Check.That(history[3]).IsEquivalentTo(s8.FaceUp(player1), s3.FaceUp(player2));
            Check.That(history[4]).IsEquivalentTo(s7.FaceUp(player1), h4.FaceUp(player2));

            var winner = ((HasWinner)gameOver).Winner;

            Check.That(winner).IsEqualTo(game.Players[1]);

            Check.That(winner.CardStack.Size).IsEqualTo(9);
            Check.That(game.DroppedCards).HasSize(0);
        }
Ejemplo n.º 4
0
        public void Drop_cards_when_battle_players_can_no_more_put_FaceUp_cards_on_the_table()
        {
            var game = GameBuilder.BuildGame(new List <List <Card> >
            {
                new List <Card> {
                    h8, s14, d7
                },
                new List <Card> {
                    h9, h14, c10
                },
                new List <Card> {
                    d2, d3, d11
                }
            }, PlayersBuilder.BuildPlayers(3, new CardsShufflerForTest()));

            var gameOver = game.Play();
            var players  = game.Players;
            var player1  = players[0];
            var player2  = players[1];
            var player3  = players[2];

            Check.That(game.TableViewsHistory).HasSize(3);

            Check.That(gameOver).IsInstanceOf <HasWinner>();
            var winner = ((HasWinner)gameOver).Winner;

            Check.That(winner).IsEqualTo(player3);
            Check.That(winner.CardStack).IsEquivalentTo(d7, c10, d11, d2);

            Check.That(game.TableViewsHistory[0]).IsEquivalentTo(d7.FaceUp(player1), c10.FaceUp(player2), d11.FaceUp(player3));
            Check.That(game.TableViewsHistory[1]).IsEquivalentTo(s14.FaceUp(player1), h14.FaceUp(player2), d3.FaceUp(player3));
            Check.That(game.TableViewsHistory[2]).IsEquivalentTo(h8.FaceDown(player1), h9.FaceDown(player2));

            Check.That(game.DroppedCards).HasSize(5);
            Check.That(game.DroppedCards).IsEquivalentTo(h8, h9, s14, h14, d3);
        }
Ejemplo n.º 5
0
        public void Should_continue_battle_if_faceUp_cards_are_all_identical()
        {
            var game = GameBuilder.BuildGame(new List <List <Card> >
            {
                new List <Card> {
                    s7, d2, h8, s11, s2
                },
                new List <Card> {
                    s6, d3, s8, s13, d2
                }
            }, PlayersBuilder.BuildPlayers(2, new CardsShufflerForTest()));

            var gameOver = game.Play();

            Check.That(gameOver).IsInstanceOf <HasWinner>();
            var hasWinner = (HasWinner)gameOver;

            var player0 = game.Players[0];

            Check.That(hasWinner.Winner).IsEqualTo(player0);

            Check.That(player0.CardStack.Size).IsEqualTo(10);
            Check.That(game.DroppedCards.Count).IsEqualTo(0);
        }
Ejemplo n.º 6
0
        public void Should_take_other_cards_in_the_same_range_When_face_up_cards_get_a_stronger_one()
        {
            var game = GameBuilder.BuildGame(new List <List <Card> >
            {
                new List <Card> {
                    s2, d5, h6
                },
                new List <Card> {
                    s3, d7, s11
                },
                new List <Card> {
                    d4, h12, d11
                }
            }, PlayersBuilder.BuildPlayers(3, new CardsShufflerForTest()));

            var gameOver = game.Play();

            var hasWinner = (HasWinner)gameOver;
            var player2   = game.Players[2];

            Check.That(hasWinner.Winner).IsEqualTo(player2);

            Check.That(player2.CardStack.Size).IsEqualTo(9);
        }