示例#1
0
        public void IsPlayable_WrongColourAndSameNumber_ReturnsTrue()
        {
            var cardInHand = new PlayableCard(new Card { Value = 5, Colour = CardColour.Yellow });
            var activeCard = new Card { Value = 5, Colour = CardColour.Blue };

            Assert.That(PlayableCards.IsPlayable(cardInHand, activeCard), Is.True);
        }
示例#2
0
 /// <summary>
 /// Loops through a players cards setting whether they're are playable with
 /// the card provided.
 /// </summary>
 public static void Process(IList<PlayableCard> cards, Card activeCard)
 {
     foreach (var playableCard in cards)
     {
         playableCard.Playable = IsPlayable(playableCard, activeCard);
     }
 }
示例#3
0
 /// <summary>
 /// Returns boolean indicating whether the playable card is playable
 /// against the active card.
 /// </summary>
 public static bool IsPlayable(PlayableCard card, Card activeCard)
 {
     if (card.Type == CardType.Wild)
         return true;
     if (card.Type == CardType.WildDraw)
         return true;
     return (card.Colour == activeCard.Colour || (card.Value < 20 && card.Value == activeCard.Value));
 }
示例#4
0
文件: Hand.cs 项目: TomDudfield/UnoTV
 /// <summary>
 /// Removes card from PlayableCards that matches the card provided.
 /// </summary>
 public void RemoveCard(Card card)
 {
     foreach (var playableCard in PlayableCards)
     {
         // does the colour & value match, if so this is the card to remove.
         if (playableCard.Colour == card.Colour && playableCard.Value == card.Value)
         {
             PlayableCards.Remove(playableCard);
             return;
         }
     }
 }
示例#5
0
        /// <summary>
        /// Plays a card, removes from face down pile and adds to played pile
        /// </summary>
        /// <param name="card"></param>
        public void PlayCard(Card card)
        {
            if (card != null)
                PlayedCards.Enqueue(card);

            if (CurrentPlayer != null && card != null)
                CurrentPlayer.Hand.RemoveCard(card);

            if (Finished)
                Started = false;
            else
                MoveToNextPlayer(card);
        }
示例#6
0
        public void PlayCard(Card card)
        {
            try
            {
                _game.PlayCard(card);
                Clients.All.cardPlayed(card);

                if (_game.Finished)
                    Clients.All.gameOver(_game.Winner);
                else
                    NotifyNextPlayer();
            }
            catch (Exception ex)
            {
                Clients.Caller.error(ex);
            }
        }
示例#7
0
 public PlayableCard(Card card, bool pickedUp = false)
 {
     Card = card;
     PickedUp = pickedUp;
 }
示例#8
0
        private void MoveToNextPlayer(Card card)
        {
            if (CurrentPlayer == null)
                CurrentPlayer = Players.First();

            if (card != null)
                CurrentPlayer.Hand.RemoveCard(card);

            var index = Players.IndexOf(CurrentPlayer);

            index = UpdateIndex(index);

            if (card != null && card.Type == CardType.Skip)
                index = UpdateIndex(index);

            CurrentPlayer = Players[index];

            foreach (var playableCard in CurrentPlayer.Hand.PlayableCards)
            {
                playableCard.PickedUp = false;
            }

            if (card != null)
            {
                if (card.Type == CardType.WildDraw)
                {
                    CurrentPlayer.Hand.PlayableCards.Add(new PlayableCard(PlayedCards.Dequeue(), true));
                    CurrentPlayer.Hand.PlayableCards.Add(new PlayableCard(PlayedCards.Dequeue(), true));
                }

                if (card.Type == CardType.Draw || card.Type == CardType.WildDraw)
                {
                    CurrentPlayer.Hand.PlayableCards.Add(new PlayableCard(PlayedCards.Dequeue(), true));
                    CurrentPlayer.Hand.PlayableCards.Add(new PlayableCard(PlayedCards.Dequeue(), true));
                    index = UpdateIndex(index);
                    CurrentPlayer = Players[index];
                }
            }

            PlayableCards.Process(CurrentPlayer.Hand.PlayableCards, CurrentCard);

            if (CurrentPlayer.Hand.HasPlayableCard == false)
            {
                CurrentPlayer.Hand.PlayableCards.Add(new PlayableCard(PlayedCards.Dequeue(), true)
                {
                    Playable = false
                });
            }
        }