Пример #1
0
        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);
        }
Пример #2
0
        public IPlayingCard Pop()
        {
            IPlayingCard tmp = this[0];

            this.RemoveAt(0);
            return(tmp);
        }
Пример #3
0
            // 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));
            }
Пример #4
0
        private int CardScore(IPlayingCard card)
        {
            int rankValue = (int)card.Rank;

            if (rankValue > 10) rankValue = 10;

            if (card.Rank == Rank.ACE)
                rankValue = 11;

            return rankValue;
        }
Пример #5
0
        public void Main(SolutionFactory Factory)
        {
            IPlayingCard obj = GetCard(Factory);

            GetCardColor(obj);
            Console.WriteLine();
            ShowVisibility(obj);
            Console.WriteLine();
            TurnOverCard(obj);
            Console.WriteLine();
            ShowCardInfo(obj);
        }
Пример #6
0
        /// <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;
            }
        }
Пример #7
0
        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.");
        }
Пример #8
0
        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);
        }
Пример #9
0
 public void AddCard(IPlayingCard card)
 {
     cards.Add(card);
 }
Пример #10
0
 private bool IsOpposite(IPlayingCard cardA, IPlayingCard cardB)
 {
     return(cardA.Color != cardB.Color);
 }
Пример #11
0
 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}");
 }
Пример #12
0
 private void ShowVisibility(IPlayingCard obj)
 {
     Console.Write("Playing card is ");
     Console.WriteLine(obj.Visibility ? "visible" : "invisible");
 }
Пример #13
0
 private void TurnOverCard(IPlayingCard obj)
 {
     Console.WriteLine("The card is turned");
     obj.TurnOver();
 }
Пример #14
0
 private void ShowCardInfo(IPlayingCard obj)
 {
     obj.Print();
     ShowVisibility(obj);
 }
Пример #15
0
 private static void DisplayCard(IPlayingCard card)
 {
     Console.Write(card.Rank.ToString() + " of " + card.Suit.ToString() + ", ");
 }