public bool IsAddingToPileLegal(IPlayingCard card, int pileNr) { if (pileNr < 0 || pileNr > 6) { throw new ArgumentOutOfRangeException("Foundation number: " + pileNr + " is out of range."); } if (card == null) { throw new ArgumentNullException("Card must NOT be NULL."); } var pile = Piles[pileNr]; if (pile == null) { throw new NullReferenceException("Pile : " + pileNr + " is Null."); } if (Piles[pileNr].Count == 0) { return(card.Rank == Rank.King); } var topPileCard = Piles[pileNr].Peek(); if (IsOpposite(topPileCard, card)) { if (card.Rank == topPileCard.Rank + 1) { return(true); } } return(false); }
public IPlayingCard Pop() { IPlayingCard tmp = this[0]; this.RemoveAt(0); return(tmp); }
// wynika z IComparable public int CompareTo(IPlayingCard other) { CardComparer cc = new CardComparer(); // albo w sposob przewidziany przez klase Comparer //IComparer<IPlayingCard> cc = CardComparer.Default; return(cc.Compare(this, other)); }
private int CardScore(IPlayingCard card) { int rankValue = (int)card.Rank; if (rankValue > 10) rankValue = 10; if (card.Rank == Rank.ACE) rankValue = 11; return rankValue; }
public void Main(SolutionFactory Factory) { IPlayingCard obj = GetCard(Factory); GetCardColor(obj); Console.WriteLine(); ShowVisibility(obj); Console.WriteLine(); TurnOverCard(obj); Console.WriteLine(); ShowCardInfo(obj); }
/// <summary> /// Suffles the deck using Fisher-Yates algorithm /// </summary> public void Shuffle() { Random rng = new Random(); int n = this.Count; while (n > 1) { int k = rng.Next(n); --n; IPlayingCard temp = this[n]; this[n] = this[k]; this[k] = temp; } }
public void Deck_PopTest() { Deck deck = new Deck(); deck.Add(AceOfSpades); deck.Add(TwoOfSpades); deck.Add(ThreeOfSpades); IPlayingCard card = deck.Pop(); Assert.AreEqual(AceOfSpades, card, "The deck did not pull the expected Ace of Spades card."); card = deck.Pop(); Assert.AreEqual(TwoOfSpades, card, "The deck did not pull the expected Two of Spades card."); card = deck.Pop(); Assert.AreEqual(ThreeOfSpades, card, "The deck did not pull the expected Three of Spades card."); Assert.AreEqual(0, deck.Count, "The deck should not have any cards left."); }
public bool IsAddingToFoundationLegal(IPlayingCard card, int foundationNr) { if (card == null) { throw new ArgumentNullException("Card must NOT be NULL."); } if (foundationNr < 0 || foundationNr > 3) { throw new ArgumentOutOfRangeException("Foundation number: " + foundationNr + " is out of range."); } var foundation = Foundations[foundationNr]; if (foundation == null) { throw new NullReferenceException("Foundation : " + foundationNr + " is Null."); } if (foundation.Count == 0) { return(card.Rank == Rank.Ace); } var topCard = foundation.Peek(); if (topCard.Suit == card.Suit) { if (card.Rank == topCard.Rank + 1) { return(true); } } return(false); }
public void AddCard(IPlayingCard card) { cards.Add(card); }
private bool IsOpposite(IPlayingCard cardA, IPlayingCard cardB) { return(cardA.Color != cardB.Color); }
private void GetCardColor(IPlayingCard obj) { Console.Write($"A Suit this card is - {Enum.GetName(typeof(CardSuit), obj.CardSuit)}"); Console.WriteLine($", so a color of card is {obj.Color}"); }
private void ShowVisibility(IPlayingCard obj) { Console.Write("Playing card is "); Console.WriteLine(obj.Visibility ? "visible" : "invisible"); }
private void TurnOverCard(IPlayingCard obj) { Console.WriteLine("The card is turned"); obj.TurnOver(); }
private void ShowCardInfo(IPlayingCard obj) { obj.Print(); ShowVisibility(obj); }
private static void DisplayCard(IPlayingCard card) { Console.Write(card.Rank.ToString() + " of " + card.Suit.ToString() + ", "); }