Example #1
0
        static void Main(string[] args)
        {
            Deck deck = new Deck();


            for (int i = 0; i <= 3; i++)
            {
                string suit = "";
                if (i == 0) suit = "hearts";
                else if (i == 1) suit = "diamonds";
                else if (i == 2) suit = "clubs";
                else if (i == 3) suit = "spades";

                for (int j = 2; j <= 14; j++)
                {
                    Card card = new Card { Suit = suit, Number = j };
                    deck.AddCard(card);
                }
            }

            deck.PrintDeck();
            deck.Shuffle();
            deck.Shuffle();
            deck.Shuffle();
            deck.PrintDeck();
        }
Example #2
0
 public void Remove(Card cardToFind)
 {
     if (m_cards.Contains(cardToFind))
     {
         m_cards.Remove(cardToFind);
     }
 }
Example #3
0
        public void Test_Constructor_SetsASuitOnTheCard_WhenGivenASuit()
        {
            //Arrange
            testSuit = Suit.Diamonds;

            //Act
            testCard = new Card(testSuit, Face.Ace , false);

            //Assert
            Assert.AreEqual(Suit.Diamonds, testCard.suit);
        }
Example #4
0
        public void Test_Constructor_SetsAFaceOnTheCard_WhenGivenAFace()
        {
            //Arrange
            testFace = Face.Jack;

            //Act
            testCard = new Card(Suit.Hearts, testFace, false);

            //Assert
            Assert.AreEqual(testFace, testCard.face);
        }
Example #5
0
        public void Test_SetCardValue_SetsAValueOnTheCard_WhenGivenANumberFace()
        {
            //Arrange
            testFace = Face.Eight;
            expectedValue = 8;

            //Act
            Card testCard = new Card(Suit.Diamonds, testFace, false);

            //Assert
            Assert.AreEqual(expectedValue, testCard.value);
        }
Example #6
0
        public void Test_Constructor_CallsSetCardValueOnce_WhenGivenAFaceAndSuit()
        {
            //Arrange
            Mock<Card> mockCard = new Mock<Card>(Suit.Hearts, Face.King, false);
               // mockCard.Setup(x => x.SetCardValue(It.IsAny<Face>()));

            //Act
            testCard = mockCard.Object;

            //Assert
            mockCard.Verify(x => x.SetCardValue(It.IsAny<Face>(), It.IsAny<bool>()), Times.Once);
        }
Example #7
0
        /// <summary>
        /// Simple method to grab cards for a standard 52 deck.
        /// 
        /// A neat way to store this would be to add to a configuration/XML file and read
        /// the cards that way. For this example, we'll stick with generating the cards with code.
        /// </summary>
        /// <returns></returns>
        private static List<Card> GetCardsForStandardDeck()
        {
            const int minValue = 1;
            const int maxValue = 13;

            var suits = GetSuitsForStandardDeck();
            var cards = new List<Card>();

            // create 13 cards for each suit
            // in this case we have four suits in a standard deck
            foreach (Suit suit in suits)
            {
                for (int value = minValue; value <= maxValue; value++)
                {
                    var card = new Card(suit, value, GetNameForCard(value));
                    cards.Add(card);
                }
            }

            return cards;
        }
Example #8
0
 public void AddCard(Card card)
 {
     deck.Add(card);
 }
Example #9
0
 public void RemoveCard(Card card)
 {
     _cards.Remove(card);
 }
Example #10
0
 public bool Contains(Card cardToFind)
 {
     return m_cards.Contains(cardToFind);
 }
Example #11
0
 public void Add(Card newCard)
 {
     m_cards.Add(newCard);
 }
Example #12
0
 public Hand(Card[] cards) 
 {
     m_cards.AddRange(cards);
 }
Example #13
0
        public void Test_SetCardValue_SetsTheValueToTen_WhenGivenAKingCard()
        {
            //Arrange
            testCard = new Card(Suit.Hearts, Face.King, false);
            testFace = Face.King;
            expectedValue = 10;

            //Act
            actualValue = testCard.SetCardValue(testFace, false);

            //Assert
            Assert.AreEqual(expectedValue, actualValue);
        }
Example #14
0
        public void Test_SetCardValue_SetsValueOfToEleven_WhenGivenAnAceAndAcesAreHigh()
        {
            //Arrange
            testCard = new Card(Suit.Spades, Face.Ace, false);
            testFace = Face.Ace;
            bool acesAreHigh = true;
            expectedValue = 11;

            //Act
            actualValue = testCard.SetCardValue(testFace, acesAreHigh);

            //Assert
            Assert.AreEqual(expectedValue, actualValue);
        }
Example #15
0
 public static string GetCardName(Card card)
 {
     return (GetCardValue(card.cardvalue) + " of " + GetCardSuit(card.cardsuit));
 }
Example #16
0
 public static bool AreCardsEqual(Card card1, Card card2)
 {
     return (card1.cardsuit == card2.cardsuit && card1.cardvalue == card2.cardvalue);
 }