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); }
/// <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); } }
/// <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)); }
/// <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; } } }
/// <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); }
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); } }
public PlayableCard(Card card, bool pickedUp = false) { Card = card; PickedUp = pickedUp; }
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 }); } }