コード例 #1
0
        public void PlayShouldCallGetTurnAndEndTurnForBothPlayers()
        {
            var firstPlayer = new ValidPlayer();
            var firstPlayerInfo = new RoundPlayerInfo(firstPlayer);
            var secondPlayer = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager = new StateManager();
            var deck = new Deck();

            SimulateGame(firstPlayerInfo, secondPlayerInfo, deck);

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            var winner = trick.Play();

            Assert.AreEqual(1, firstPlayer.GetTurnCalledCount);
            Assert.AreEqual(1, secondPlayer.GetTurnCalledCount);
            Assert.AreEqual(1, firstPlayer.EndTurnCalledCount);
            Assert.AreEqual(1, secondPlayer.EndTurnCalledCount);

            Assert.IsNotNull(firstPlayer.GetTurnContextObject);
            Assert.IsNotNull(secondPlayer.GetTurnContextObject);
            Assert.IsNotNull(firstPlayer.EndTurnContextObject);
            Assert.IsNotNull(secondPlayer.EndTurnContextObject);

            Assert.IsNotNull(firstPlayer.EndTurnContextObject.FirstPlayedCard);
            Assert.IsNotNull(firstPlayer.EndTurnContextObject.SecondPlayedCard);
            Assert.IsNotNull(secondPlayer.EndTurnContextObject.FirstPlayedCard);
            Assert.IsNotNull(secondPlayer.EndTurnContextObject.SecondPlayedCard);

            Assert.IsTrue(winner == firstPlayerInfo || winner == secondPlayerInfo);
        }
コード例 #2
0
 public void GameClosedByShouldReturnSecondPlayerWhenTheSecondPlayerIsGameCloser()
 {
     var firstRoundPlayerInfo = new RoundPlayerInfo(new Mock<IPlayer>().Object);
     var secondRoundPlayerInfo = new RoundPlayerInfo(new Mock<IPlayer>().Object) { GameCloser = true };
     var roundResult = new RoundResult(firstRoundPlayerInfo, secondRoundPlayerInfo);
     Assert.AreEqual(PlayerPosition.SecondPlayer, roundResult.GameClosedBy);
 }
コード例 #3
0
        public void RoundPointsShouldReturn20WhenAnnounceOfTwentyAdded()
        {
            var roundPlayerInfo = new RoundPlayerInfo(new Mock <BasePlayer>().Object);

            roundPlayerInfo.Announces.Add(Announce.Twenty);
            Assert.Equal(20, roundPlayerInfo.RoundPoints);
        }
コード例 #4
0
 public void GameClosedByShouldReturnNoOnePlayerWhenNoneOfThePlayersIsGameCloser()
 {
     var firstRoundPlayerInfo = new RoundPlayerInfo(new Mock<IPlayer>().Object);
     var secondRoundPlayerInfo = new RoundPlayerInfo(new Mock<IPlayer>().Object);
     var roundResult = new RoundResult(firstRoundPlayerInfo, secondRoundPlayerInfo);
     Assert.AreEqual(PlayerPosition.NoOne, roundResult.GameClosedBy);
 }
コード例 #5
0
        public void RoundPointsShouldReturn40WhenAnnounceOfFortyAdded()
        {
            var roundPlayerInfo = new RoundPlayerInfo(new Mock <BasePlayer>().Object);

            roundPlayerInfo.Announces.Add(Announce.Forty);
            Assert.AreEqual(40, roundPlayerInfo.RoundPoints);
        }
コード例 #6
0
 public void AddCardShouldCallPlayersAddCardMethod()
 {
     var player = new Mock<BasePlayer>();
     var roundPlayerInfo = new RoundPlayerInfo(player.Object);
     var card = new Card(CardSuit.Club, CardType.Ace);
     roundPlayerInfo.AddCard(card);
     player.Verify(x => x.AddCard(card), Times.Once());
 }
コード例 #7
0
 public void AddCardShouldAddTheCardToTheLocalCardsList()
 {
     var player = new Mock<BasePlayer>();
     var roundPlayerInfo = new RoundPlayerInfo(player.Object);
     var card = new Card(CardSuit.Club, CardType.Ace);
     roundPlayerInfo.AddCard(card);
     Assert.IsTrue(roundPlayerInfo.Cards.Contains(card));
 }
コード例 #8
0
ファイル: RoundResultTests.cs プロジェクト: ekov1/Homeworks
        public void GameClosedByShouldReturnNoOnePlayerWhenNoneOfThePlayersIsGameCloser()
        {
            var firstRoundPlayerInfo  = new RoundPlayerInfo(new Mock <IPlayer>().Object);
            var secondRoundPlayerInfo = new RoundPlayerInfo(new Mock <IPlayer>().Object);
            var roundResult           = new RoundResult(firstRoundPlayerInfo, secondRoundPlayerInfo);

            Assert.AreEqual(PlayerPosition.NoOne, roundResult.GameClosedBy);
        }
コード例 #9
0
 public void ConstructorShouldSetProperties()
 {
     var firstRoundPlayerInfo = new RoundPlayerInfo(new Mock<IPlayer>().Object);
     var secondRoundPlayerInfo = new RoundPlayerInfo(new Mock<IPlayer>().Object);
     var roundResult = new RoundResult(firstRoundPlayerInfo, secondRoundPlayerInfo);
     Assert.AreEqual(firstRoundPlayerInfo, roundResult.FirstPlayer);
     Assert.AreEqual(secondRoundPlayerInfo, roundResult.SecondPlayer);
 }
コード例 #10
0
        public void RoundPointsShouldReturn0WhenAnnounceNoneAdded()
        {
            var roundPlayerInfo = new RoundPlayerInfo(new Mock<BasePlayer>().Object);
            Assert.AreEqual(0, roundPlayerInfo.RoundPoints);

            roundPlayerInfo.Announces.Add(Announce.None);
            Assert.AreEqual(0, roundPlayerInfo.RoundPoints);
        }
コード例 #11
0
        public void AddCardShouldCallPlayersAddCardMethod()
        {
            var player          = new Mock <BasePlayer>();
            var roundPlayerInfo = new RoundPlayerInfo(player.Object);
            var card            = new Card(CardSuit.Club, CardType.Ace);

            roundPlayerInfo.AddCard(card);
            player.Verify(x => x.AddCard(card), Times.Once());
        }
コード例 #12
0
        public void RoundPointsShouldReturn0WhenAnnounceNoneAdded()
        {
            var roundPlayerInfo = new RoundPlayerInfo(new Mock <BasePlayer>().Object);

            Assert.AreEqual(0, roundPlayerInfo.RoundPoints);

            roundPlayerInfo.Announces.Add(Announce.None);
            Assert.AreEqual(0, roundPlayerInfo.RoundPoints);
        }
コード例 #13
0
ファイル: RoundResultTests.cs プロジェクト: ekov1/Homeworks
        public void ConstructorShouldSetProperties()
        {
            var firstRoundPlayerInfo  = new RoundPlayerInfo(new Mock <IPlayer>().Object);
            var secondRoundPlayerInfo = new RoundPlayerInfo(new Mock <IPlayer>().Object);
            var roundResult           = new RoundResult(firstRoundPlayerInfo, secondRoundPlayerInfo);

            Assert.AreEqual(firstRoundPlayerInfo, roundResult.FirstPlayer);
            Assert.AreEqual(secondRoundPlayerInfo, roundResult.SecondPlayer);
        }
コード例 #14
0
        public void AddCardShouldAddTheCardToTheLocalCardsList()
        {
            var player          = new Mock <BasePlayer>();
            var roundPlayerInfo = new RoundPlayerInfo(player.Object);
            var card            = new Card(CardSuit.Club, CardType.Ace);

            roundPlayerInfo.AddCard(card);
            Assert.IsTrue(roundPlayerInfo.Cards.Contains(card));
        }
コード例 #15
0
        public void RoundPointsShouldReturnCorrectValueOfCards()
        {
            var roundPlayerInfo = new RoundPlayerInfo(new Mock <BasePlayer>().Object);
            var card1           = new Card(CardSuit.Diamond, CardType.Jack);
            var card2           = new Card(CardSuit.Diamond, CardType.Ace);

            roundPlayerInfo.TrickCards.Add(card1);
            roundPlayerInfo.TrickCards.Add(card2);
            Assert.AreEqual(card1.GetValue() + card2.GetValue(), roundPlayerInfo.RoundPoints);
        }
コード例 #16
0
        public void NoTricksPlayerShouldReturnSecondPlayerWhenOnlyFirstPlayerHasTricks()
        {
            var firstRoundPlayerInfo = new RoundPlayerInfo(new Mock<IPlayer>().Object);
            var secondRoundPlayerInfo = new RoundPlayerInfo(new Mock<IPlayer>().Object);
            var roundResult = new RoundResult(firstRoundPlayerInfo, secondRoundPlayerInfo);

            firstRoundPlayerInfo.TrickCards.Add(new Card(CardSuit.Club, CardType.Ace));

            Assert.AreEqual(PlayerPosition.SecondPlayer, roundResult.NoTricksPlayer);
        }
コード例 #17
0
ファイル: RoundResultTests.cs プロジェクト: ekov1/Homeworks
        public void NoTricksPlayerShouldReturnSecondPlayerWhenOnlyFirstPlayerHasTricks()
        {
            var firstRoundPlayerInfo  = new RoundPlayerInfo(new Mock <IPlayer>().Object);
            var secondRoundPlayerInfo = new RoundPlayerInfo(new Mock <IPlayer>().Object);
            var roundResult           = new RoundResult(firstRoundPlayerInfo, secondRoundPlayerInfo);

            firstRoundPlayerInfo.TrickCards.Add(new Card(CardSuit.Club, CardType.Ace));

            Assert.AreEqual(PlayerPosition.SecondPlayer, roundResult.NoTricksPlayer);
        }
コード例 #18
0
 public void HasAtLeastOneTrickShouldReturnTrueAfterAddingCardToTricksAndFalseBeforeThat()
 {
     var player = new Mock<BasePlayer>();
     var roundPlayerInfo = new RoundPlayerInfo(player.Object);
     Assert.IsFalse(roundPlayerInfo.HasAtLeastOneTrick);
     roundPlayerInfo.TrickCards.Add(new Card(CardSuit.Club, CardType.Ace));
     Assert.IsTrue(roundPlayerInfo.HasAtLeastOneTrick);
     roundPlayerInfo.TrickCards.Add(new Card(CardSuit.Club, CardType.Ten));
     Assert.IsTrue(roundPlayerInfo.HasAtLeastOneTrick);
 }
コード例 #19
0
        public void NoTricksPlayerShouldReturnNoOnePlayerWhenBothPlayerHaveTricks()
        {
            var firstRoundPlayerInfo  = new RoundPlayerInfo(new Mock <IPlayer>().Object);
            var secondRoundPlayerInfo = new RoundPlayerInfo(new Mock <IPlayer>().Object);
            var roundResult           = new RoundResult(firstRoundPlayerInfo, secondRoundPlayerInfo);

            firstRoundPlayerInfo.TrickCards.Add(Card.GetCard(CardSuit.Club, CardType.Ace));
            secondRoundPlayerInfo.TrickCards.Add(Card.GetCard(CardSuit.Club, CardType.Ten));

            Assert.Equal(PlayerPosition.NoOne, roundResult.NoTricksPlayer);
        }
コード例 #20
0
        public void RoundPointsShouldReturnCorrectValueOfCardsAndAnnounces()
        {
            var roundPlayerInfo = new RoundPlayerInfo(new Mock <BasePlayer>().Object);
            var card1           = Card.GetCard(CardSuit.Diamond, CardType.Jack);
            var card2           = Card.GetCard(CardSuit.Diamond, CardType.Ace);

            roundPlayerInfo.TrickCards.Add(card1);
            roundPlayerInfo.TrickCards.Add(card2);
            roundPlayerInfo.Announces.Add(Announce.Twenty);
            Assert.Equal(card1.GetValue() + card2.GetValue() + 20, roundPlayerInfo.RoundPoints);
        }
コード例 #21
0
ファイル: RoundResultTests.cs プロジェクト: ekov1/Homeworks
        public void GameClosedByShouldReturnSecondPlayerWhenTheSecondPlayerIsGameCloser()
        {
            var firstRoundPlayerInfo  = new RoundPlayerInfo(new Mock <IPlayer>().Object);
            var secondRoundPlayerInfo = new RoundPlayerInfo(new Mock <IPlayer>().Object)
            {
                GameCloser = true
            };
            var roundResult = new RoundResult(firstRoundPlayerInfo, secondRoundPlayerInfo);

            Assert.AreEqual(PlayerPosition.SecondPlayer, roundResult.GameClosedBy);
        }
コード例 #22
0
        public void HasAtLeastOneTrickShouldReturnTrueAfterAddingCardToTricksAndFalseBeforeThat()
        {
            var player          = new Mock <BasePlayer>();
            var roundPlayerInfo = new RoundPlayerInfo(player.Object);

            Assert.IsFalse(roundPlayerInfo.HasAtLeastOneTrick);
            roundPlayerInfo.TrickCards.Add(new Card(CardSuit.Club, CardType.Ace));
            Assert.IsTrue(roundPlayerInfo.HasAtLeastOneTrick);
            roundPlayerInfo.TrickCards.Add(new Card(CardSuit.Club, CardType.Ten));
            Assert.IsTrue(roundPlayerInfo.HasAtLeastOneTrick);
        }
コード例 #23
0
 public void ConstructorShouldSetDefaultPropertyValues()
 {
     var player = new Mock<BasePlayer>();
     var roundPlayerInfo = new RoundPlayerInfo(player.Object);
     Assert.AreSame(player.Object, roundPlayerInfo.Player);
     Assert.IsNotNull(roundPlayerInfo.Cards);
     Assert.IsNotNull(roundPlayerInfo.TrickCards);
     Assert.IsNotNull(roundPlayerInfo.Announces);
     Assert.IsFalse(roundPlayerInfo.GameCloser);
     Assert.AreEqual(0, roundPlayerInfo.RoundPoints);
     Assert.IsFalse(roundPlayerInfo.HasAtLeastOneTrick);
 }
コード例 #24
0
        private static void SimulateGame(RoundPlayerInfo firstPlayer, RoundPlayerInfo secondPlayer, Deck deck)
        {
            for (var i = 0; i < 6; i++)
            {
                firstPlayer.AddCard(deck.GetNextCard());
            }

            for (var i = 0; i < 6; i++)
            {
                secondPlayer.AddCard(deck.GetNextCard());
            }
        }
コード例 #25
0
ファイル: Trick.cs プロジェクト: NotDemons/NotDemonsRepo
 public Trick(
     RoundPlayerInfo firstToPlay,
     RoundPlayerInfo secondToPlay,
     IStateManager stateManager,
     IDeck deck,
     IGameRules gameRules)
 {
     this.firstToPlay = firstToPlay;
     this.secondToPlay = secondToPlay;
     this.stateManager = stateManager;
     this.deck = deck;
     this.gameRules = gameRules;
 }
コード例 #26
0
        public void ConstructorShouldSetDefaultPropertyValues()
        {
            var player          = new Mock <BasePlayer>();
            var roundPlayerInfo = new RoundPlayerInfo(player.Object);

            Assert.AreSame(player.Object, roundPlayerInfo.Player);
            Assert.IsNotNull(roundPlayerInfo.Cards);
            Assert.IsNotNull(roundPlayerInfo.TrickCards);
            Assert.IsNotNull(roundPlayerInfo.Announces);
            Assert.IsFalse(roundPlayerInfo.GameCloser);
            Assert.AreEqual(0, roundPlayerInfo.RoundPoints);
            Assert.IsFalse(roundPlayerInfo.HasAtLeastOneTrick);
        }
コード例 #27
0
ファイル: Round.cs プロジェクト: NotDemons/NotDemonsRepo
        private void CallStartRoundAndDealCards(RoundPlayerInfo player, int playerTotalPoints, int opponentTotalPoints)
        {
            var cards = new List<Card>();

            // TODO: 6 should be constant
            for (var i = 0; i < 6; i++)
            {
                var card = this.deck.GetNextCard();
                cards.Add(card);
                player.Cards.Add(card);
            }

            player.Player.StartRound(cards, this.deck.TrumpCard, playerTotalPoints, opponentTotalPoints);
        }
コード例 #28
0
ファイル: Round.cs プロジェクト: NotDemons/NotDemonsRepo
        public Round(
            IPlayer firstPlayer,
            IPlayer secondPlayer,
            IGameRules gameRules,
            PlayerPosition firstToPlay = PlayerPosition.FirstPlayer)
        {
            this.gameRules = gameRules;
            this.deck = new Deck();
            this.stateManager = new StateManager();

            this.firstPlayer = new RoundPlayerInfo(firstPlayer);
            this.secondPlayer = new RoundPlayerInfo(secondPlayer);

            this.firstToPlay = firstToPlay;
        }
コード例 #29
0
        public void PlayShouldCallGetTurnOnlyForFirstPlayerWhenTheFirstPlayerGoesOutByAnnounce()
        {
            var firstPlayer = new ValidPlayer();
            var firstPlayerInfo = new RoundPlayerInfo(firstPlayer);
            var secondPlayer = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager = new StateManager();
            var deck = new Deck();

            // 53 points in firstPlayerInfo.TrickCards
            firstPlayerInfo.TrickCards.Add(new Card(CardSuit.Diamond, CardType.Ace));
            firstPlayerInfo.TrickCards.Add(new Card(CardSuit.Diamond, CardType.Ten));
            firstPlayerInfo.TrickCards.Add(new Card(CardSuit.Spade, CardType.Ace));
            firstPlayerInfo.TrickCards.Add(new Card(CardSuit.Club, CardType.Ace));
            firstPlayerInfo.TrickCards.Add(new Card(CardSuit.Club, CardType.Ten));

            // Add cards for announcing 20
            firstPlayerInfo.AddCard(new Card(CardSuit.Heart, CardType.King));
            firstPlayerInfo.AddCard(new Card(CardSuit.Heart, CardType.Queen));
            stateManager.SetState(new MoreThanTwoCardsLeftRoundState(stateManager));

            secondPlayerInfo.AddCard(new Card(CardSuit.Heart, CardType.Ten));
            secondPlayerInfo.AddCard(new Card(CardSuit.Heart, CardType.Ace));

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            var winner = trick.Play();

            Assert.AreEqual(1, firstPlayer.GetTurnCalledCount);
            Assert.AreEqual(0, secondPlayer.GetTurnCalledCount);
            Assert.AreEqual(1, firstPlayer.EndTurnCalledCount);
            Assert.AreEqual(1, secondPlayer.EndTurnCalledCount);
            Assert.AreSame(firstPlayerInfo, winner);

            Assert.IsTrue(firstPlayerInfo.HasAtLeastOneTrick);
            Assert.IsFalse(secondPlayerInfo.HasAtLeastOneTrick);

            Assert.IsTrue(winner.RoundPoints == 73 || winner.RoundPoints == 93);
            Assert.IsTrue(winner.RoundPoints == 73 || winner.RoundPoints == 93);
        }
コード例 #30
0
ファイル: Trick.cs プロジェクト: NotDemons/NotDemonsRepo
        private static PlayerAction GetPlayerAction(RoundPlayerInfo playerInfo, PlayerTurnContext context)
        {
            var action = playerInfo.Player.GetTurn(context.DeepClone());
            var isActionValid = PlayerActionValidator.Instance.IsValid(action, context, playerInfo.Cards);
            if (!isActionValid)
            {
                throw new InternalGameException($"Invalid action played from {playerInfo.Player.Name}");
            }

            return action;
        }
コード例 #31
0
ファイル: Round.cs プロジェクト: NotDemons/NotDemonsRepo
 private void GiveCardToPlayer(RoundPlayerInfo player)
 {
     var card = this.deck.GetNextCard();
     player.AddCard(card);
 }
コード例 #32
0
ファイル: Trick.cs プロジェクト: NotDemons/NotDemonsRepo
        private PlayerAction GetFirstPlayerAction(RoundPlayerInfo playerInfo, PlayerTurnContext context)
        {
            while (true)
            {
                var action = GetPlayerAction(playerInfo, context);
                switch (action.Type)
                {
                    case PlayerActionType.ChangeTrump:
                        {
                            var oldTrumpCard = this.deck.TrumpCard;
                            var nineOfTrump = new Card(oldTrumpCard.Suit, CardType.Nine);

                            this.deck.ChangeTrumpCard(nineOfTrump);
                            context.TrumpCard = nineOfTrump;

                            // Only swap cards from the local cards list (player should swap its own cards)
                            playerInfo.Cards.Remove(nineOfTrump);
                            playerInfo.Cards.Add(oldTrumpCard);
                            continue;
                        }

                    case PlayerActionType.CloseGame:
                        {
                            this.stateManager.State.Close();
                            context.State = this.stateManager.State;
                            playerInfo.GameCloser = true;
                            continue;
                        }

                    case PlayerActionType.PlayCard:
                        {
                            if (action.Announce != Announce.None)
                            {
                                playerInfo.Announces.Add(action.Announce);
                            }

                            return action;
                        }
                }
            }
        }
コード例 #33
0
 public RoundResult(RoundPlayerInfo firstPlayer, RoundPlayerInfo secondPlayer)
 {
     this.FirstPlayer = firstPlayer;
     this.SecondPlayer = secondPlayer;
 }
コード例 #34
0
 public void RoundPointsShouldReturn40WhenAnnouncesOfTwentyAndFortyAdded()
 {
     var roundPlayerInfo = new RoundPlayerInfo(new Mock<BasePlayer>().Object);
     roundPlayerInfo.Announces.Add(Announce.Twenty);
     roundPlayerInfo.Announces.Add(Announce.Forty);
     Assert.AreEqual(60, roundPlayerInfo.RoundPoints);
 }
コード例 #35
0
 public void RoundPointsShouldReturnCorrectValueOfCards()
 {
     var roundPlayerInfo = new RoundPlayerInfo(new Mock<BasePlayer>().Object);
     var card1 = new Card(CardSuit.Diamond, CardType.Jack);
     var card2 = new Card(CardSuit.Diamond, CardType.Ace);
     roundPlayerInfo.TrickCards.Add(card1);
     roundPlayerInfo.TrickCards.Add(card2);
     Assert.AreEqual(card1.GetValue() + card2.GetValue(), roundPlayerInfo.RoundPoints);
 }
コード例 #36
0
        public void PlayShouldCloseTheGameWhenPlayerPlaysCloseGameAction()
        {
            var firstPlayer = new ValidPlayer(PlayerActionType.CloseGame);
            var firstPlayerInfo = new RoundPlayerInfo(firstPlayer);
            var secondPlayer = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager = new StateManager();
            stateManager.SetState(new MoreThanTwoCardsLeftRoundState(stateManager));
            var deck = new Deck();

            SimulateGame(firstPlayerInfo, secondPlayerInfo, deck);

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            trick.Play();

            Assert.IsTrue(firstPlayerInfo.GameCloser);
            Assert.IsFalse(secondPlayerInfo.GameCloser);
            Assert.IsInstanceOf<FinalRoundState>(stateManager.State);
            Assert.IsInstanceOf<FinalRoundState>(secondPlayer.GetTurnContextObject.State);
        }
コード例 #37
0
        public void PlayShouldChangeTheDeckTrumpWhenPlayerPlaysChangeTrumpAction()
        {
            var firstPlayer = new ValidPlayer(PlayerActionType.ChangeTrump);
            var firstPlayerInfo = new RoundPlayerInfo(firstPlayer);
            var secondPlayer = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager = new StateManager();
            stateManager.SetState(new MoreThanTwoCardsLeftRoundState(stateManager));
            var deck = new Deck();
            var trumpSuit = deck.TrumpCard.Suit;

            var oldTrumpCard = deck.TrumpCard.DeepClone();
            var nineOfTrump = new Card(trumpSuit, CardType.Nine);

            firstPlayerInfo.AddCard(nineOfTrump);
            secondPlayerInfo.AddCard(
                new Card(trumpSuit == CardSuit.Heart ? CardSuit.Club : CardSuit.Heart, CardType.Ace));

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            trick.Play();

            Assert.AreEqual(nineOfTrump, deck.TrumpCard);
            Assert.AreEqual(nineOfTrump, secondPlayer.GetTurnContextObject.TrumpCard);
            Assert.IsTrue(firstPlayerInfo.TrickCards.Contains(oldTrumpCard), "Trick cards should contain oldTrumpCard");
            Assert.IsFalse(firstPlayerInfo.Cards.Contains(nineOfTrump));
            Assert.IsFalse(
                firstPlayer.CardsCollection.Contains(nineOfTrump),
                "Player contains nine of trump after changing trump card");
        }
コード例 #38
0
        private static void SimulateGame(RoundPlayerInfo firstPlayer, RoundPlayerInfo secondPlayer, Deck deck)
        {
            for (var i = 0; i < 6; i++)
            {
                firstPlayer.AddCard(deck.GetNextCard());
            }

            for (var i = 0; i < 6; i++)
            {
                secondPlayer.AddCard(deck.GetNextCard());
            }
        }
コード例 #39
0
        public void PlayShouldThrowAnExceptionWhenPlayerReturnsNullAction()
        {
            var firstPlayer = new Mock<IPlayer>();
            firstPlayer.Setup(x => x.GetTurn(It.IsAny<PlayerTurnContext>())).Returns((PlayerAction)null);
            var firstPlayerInfo = new RoundPlayerInfo(firstPlayer.Object);

            var secondPlayer = new Mock<IPlayer>();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer.Object);

            var stateManager = new StateManager();
            var deck = new Deck();

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            trick.Play();
        }
コード例 #40
0
        public void PlayShouldThrowAnExceptionWhenPlayerPlaysInvalidCard()
        {
            var firstPlayer = new Mock<IPlayer>();
            firstPlayer.Setup(x => x.GetTurn(It.IsAny<PlayerTurnContext>()))
                .Returns(PlayerAction.PlayCard(new Card(CardSuit.Club, CardType.Ace)));
            var firstPlayerInfo = new RoundPlayerInfo(firstPlayer.Object);

            var secondPlayer = new Mock<IPlayer>();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer.Object);

            var stateManager = new StateManager();
            var deck = new Deck();

            firstPlayerInfo.AddCard(new Card(CardSuit.Heart, CardType.King));
            secondPlayerInfo.AddCard(new Card(CardSuit.Heart, CardType.Ace));

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            trick.Play();
        }
コード例 #41
0
        public void PlayShouldThrowAnExceptionWhenClosingTheGameAndNineOfTrumpsIsMissing()
        {
            var firstPlayer = new ValidPlayer(PlayerActionType.ChangeTrump);
            var firstPlayerInfo = new RoundPlayerInfo(firstPlayer);
            var secondPlayer = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager = new StateManager();
            stateManager.SetState(new MoreThanTwoCardsLeftRoundState(stateManager));
            var deck = new Deck();
            var trumpSuit = deck.TrumpCard.Suit;

            firstPlayerInfo.AddCard(new Card(trumpSuit, CardType.Jack));
            secondPlayerInfo.AddCard(new Card(CardSuit.Heart, CardType.Ace));

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            trick.Play();
        }
コード例 #42
0
        public void PlayShouldCorrectlyDetermineTheWinner()
        {
            var firstPlayer = new ValidPlayer();
            var firstPlayerInfo = new RoundPlayerInfo(firstPlayer);
            var secondPlayer = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager = new StateManager();
            var deck = new Deck();

            firstPlayerInfo.AddCard(new Card(CardSuit.Heart, CardType.Nine));
            secondPlayerInfo.AddCard(new Card(deck.TrumpCard.Suit, CardType.Jack));

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            var winner = trick.Play();

            Assert.IsTrue(winner == secondPlayerInfo);
            Assert.AreEqual(2, winner.RoundPoints);
            Assert.AreEqual(2, winner.TrickCards.Count);
            Assert.IsTrue(winner.TrickCards.Contains(new Card(CardSuit.Heart, CardType.Nine)));
            Assert.IsTrue(winner.TrickCards.Contains(new Card(deck.TrumpCard.Suit, CardType.Jack)));
            Assert.AreEqual(0, firstPlayerInfo.TrickCards.Count);

            Assert.AreEqual(0, firstPlayer.EndTurnContextObject.FirstPlayerRoundPoints);
            Assert.AreEqual(2, firstPlayer.EndTurnContextObject.SecondPlayerRoundPoints);
            Assert.AreEqual(0, secondPlayer.EndTurnContextObject.FirstPlayerRoundPoints);
            Assert.AreEqual(2, secondPlayer.EndTurnContextObject.SecondPlayerRoundPoints);

            Assert.AreEqual(0, firstPlayer.GetTurnContextObject.FirstPlayerRoundPoints);
            Assert.AreEqual(0, firstPlayer.GetTurnContextObject.SecondPlayerRoundPoints);
            Assert.AreEqual(0, secondPlayer.GetTurnContextObject.FirstPlayerRoundPoints);
            Assert.AreEqual(0, secondPlayer.GetTurnContextObject.SecondPlayerRoundPoints);
        }
コード例 #43
0
        public void PlayShouldProvideCorrectPlayerTurnContextToPlayers()
        {
            var firstPlayer = new ValidPlayer();
            var firstPlayerInfo = new RoundPlayerInfo(firstPlayer);
            var secondPlayer = new ValidPlayer();
            var secondPlayerInfo = new RoundPlayerInfo(secondPlayer);
            var stateManager = new StateManager();
            var deck = new Deck();

            firstPlayerInfo.AddCard(new Card(CardSuit.Heart, CardType.King));
            firstPlayerInfo.AddCard(new Card(CardSuit.Heart, CardType.Queen));
            stateManager.SetState(new MoreThanTwoCardsLeftRoundState(stateManager));

            secondPlayerInfo.AddCard(new Card(CardSuit.Diamond, CardType.Ten));
            secondPlayerInfo.AddCard(new Card(CardSuit.Diamond, CardType.Ace));

            var trick = new Trick(firstPlayerInfo, secondPlayerInfo, stateManager, deck, GameRulesProvider.Santase);
            trick.Play();

            Assert.IsTrue(firstPlayer.GetTurnContextObject.IsFirstPlayerTurn);
            Assert.IsFalse(secondPlayer.GetTurnContextObject.IsFirstPlayerTurn);
            Assert.IsTrue(secondPlayer.GetTurnContextObject.FirstPlayerAnnounce != Announce.None);
            Assert.IsNotNull(secondPlayer.GetTurnContextObject.FirstPlayedCard);
            Assert.AreEqual(CardSuit.Heart, secondPlayer.GetTurnContextObject.FirstPlayedCard.Suit);

            Assert.IsTrue(
                secondPlayer.GetTurnContextObject.FirstPlayerRoundPoints == 20
                || secondPlayer.GetTurnContextObject.FirstPlayerRoundPoints == 40);
        }