예제 #1
0
        public void IsLegal_ReturnTrueIfThereIsNoStartCard()
        {
            var cards = new[]
            {
                new Card(CardType.Blue, 1, 0),
                new Card(CardType.Blue, 2, 0),
                new Card(CardType.Red, 3, 0)
            };
            var hand = new Hand(cards);

            Assert.IsTrue(PlayRule.IsLegal(hand, cards[2], null), "All cards should be allowed");
        }
예제 #2
0
        public void IsLegal_ReturnsFalseIfCardDoesntExist()
        {
            var cards = new[]
            {
                new Card(CardType.Blue, 1, 0),
                new Card(CardType.Blue, 2, 0)
            };
            var hand = new Hand(cards);

            Assert.IsFalse(PlayRule.IsLegal(hand, new Card(CardType.Red, 1, 0), null), "Different color");
            Assert.IsFalse(PlayRule.IsLegal(hand, new Card(CardType.Blue, 3, 0), null), "Different number");
            Assert.IsFalse(PlayRule.IsLegal(hand, new Card(CardType.Red, 3, 0), null), "Different color & number");
        }
예제 #3
0
        public void IsLegal_ReturnsFalseIfUserHasCorrectColorButPlaysDifferent()
        {
            var start = new Card(CardType.Blue, 6, 0);
            var cards = new[]
            {
                new Card(CardType.Blue, 1, 0),
                new Card(CardType.Blue, 2, 0),
                new Card(CardType.Red, 3, 0)
            };
            var hand = new Hand(cards);

            Assert.IsFalse(PlayRule.IsLegal(hand, cards[2], start), "User lied");
        }
예제 #4
0
    private List <Play> AskMoves()
    {
        var playedCards = new List <Play>();

        foreach (var seat in _seats)
        {
            var card = seat.Player.Play(playedCards.Select(p => p.Card).ToArray());
            //Check rule validity
            var playerHand = seat.Hand;
            if (!PlayRule.IsLegal(playerHand, card, playedCards.Select(p => p.Card).FirstOrDefault()))
            {
                throw new Exception("Illegal move");
            }
            //Remove card from player
            playerHand.RemoveCard(card);
            playedCards.Add(new Play(seat.Index, card));
        }

        return(playedCards);
    }