Ejemplo n.º 1
0
        public void OneDeck_DeckContains52Cards_IsTrue()
        {
            Deck testdeck = new Deck();
            testdeck.InitializeFullDeck();

            Assert.AreEqual(testdeck.Cards.Count == 52, true);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //delcare new deck
            var Deck = new Deck();

            //shuffle the cards
            Deck.Shuffle();

            //deal cards
            List<Cards> ListofCards = new List<Cards>();
            ListofCards = Deck.Deal();
            Console.WriteLine("\n\nDealt Cards: ");
            Console.WriteLine();
            foreach (var item in ListofCards)
            {
                item.DealFromDeck();
            }

            //deal cards
            List<Cards> ListofCards2 = new List<Cards>();
            ListofCards2 = Deck.Deal();
            Console.WriteLine("\n\nDealt Cards: ");
            Console.WriteLine();
            foreach (var item in ListofCards2)
            {
                item.DealFromDeck();
            }

            //keep window open
            Console.ReadKey();
        }
        public void OneDeck_ItemsUnique_IsTrue()
        {
            Deck testdeck = new Deck();

            var my = testdeck.TupCards.ToArray();
            CollectionAssert.AllItemsAreUnique(my, "all items are not unique");
        }
Ejemplo n.º 4
0
 public void OneDeck_DeckShuffled_WillNotBeSorted()
 {
     Deck testdeck = new Deck();
     testdeck.InitializeFullDeck();
     testdeck.Shuffle();
     Assert.AreEqual(testdeck.IsSorted(), false);
 }
        public void OneDeck_AllItemsAreNotNull_NoCardsAreNull()
        {
            Deck testdeck = new Deck();

            var my = testdeck.TupCards.ToArray();
            CollectionAssert.AllItemsAreNotNull(my, "all items are not null");
        }
Ejemplo n.º 6
0
 public void OneDeck_InitializeThenShuffle_NoDuplicates()
 {
     Deck testdeck = new Deck();
     testdeck.InitializeFullDeck();
     testdeck.Shuffle();
     Assert.AreEqual(testdeck.AreCardsUnique(), true);
 }
Ejemplo n.º 7
0
		public static void Main()
		{
			IDeck deck = new Deck();
			IEnumerable<Card> hand = deck.TakeCards(13);

			Console.WriteLine("Displaying hand:");
			foreach (Card card in hand)
				Console.WriteLine(card.ToString());
			Console.ReadLine();

			Console.WriteLine("Displaying remaining deck:");
			Console.Write(deck.ToString());
			Console.ReadLine();

			deck.Shuffle();

			Console.WriteLine("Displaying remaining, shuffled deck:");
			Console.Write(deck.ToString());
			Console.ReadLine();

			Card takenCard = deck.TakeCard();

			Console.WriteLine("Displaying next card delt from deck:");
			Console.WriteLine(takenCard.ToString());
			Console.ReadLine();

			Console.WriteLine("Displaying remaining deck:");
			Console.Write(deck.ToString());
			Console.ReadLine();
		}
Ejemplo n.º 8
0
        /// <summary>
        /// Build a new deck based on the type of deck requested.
        /// </summary>
        /// <param name="deckType"></param>
        /// <returns></returns>
        public static IDeck BuildDeck(DeckType deckType)
        {
            IDeck deck = null;

            switch (deckType)
            {
                case DeckType.Standard52:
                    deck = new Deck(GetCardsForStandardDeck(), new FisherYatesModernShuffler<Card>());
                    break;
                case DeckType.Piquet:
                    // no implementation for this example
                    break;
                case DeckType.MexicanStud:
                    // no implementation for this example
                    break;
                case DeckType.FiveCardStud:
                    // no implementation for this example
                    break;
                case DeckType.CatanResourceCards:
                    // no implementation for this example
                    break;
                case DeckType.CatanDevelopmentCards:
                    // no implementation for this example
                    break;
            }

            return deck;
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Deck deck1 = new Deck();

            /* Read The Initalized Cards */
            foreach (var card in deck1.TupCards)
            {
                Console.Write("drew {0} of {1}\n", Card.GetCardValue(card.Item1), Card.GetCardSuit(card.Item2));
            }

            /* Shuffle Cards */
            Console.Write("\n\nShuffle The Deck\n\n");
            deck1.Shuffle();

            /* Read Shuffled Cards */
            foreach (var card in deck1.TupCards)
            {
                Console.Write("drew {0} of {1}\n", Card.GetCardValue(card.Item1), Card.GetCardSuit(card.Item2));
            }

            /* Sort Them Again */
            Console.Write("\n\nSort The Deck\n\n");
            deck1.Sort();
            foreach (var card in deck1.TupCards)
            {
                Console.Write("drew {0} of {1}\n", Card.GetCardValue(card.Item1), Card.GetCardSuit(card.Item2));
            }

            Console.ReadLine();
        }
        public void TwoDecks_ShuffleADeckAndCompareToSortedDeck()
        {
            Deck testdeck = new Deck();

            testdeck.Shuffle();
            var my = testdeck.TupCards.ToArray();
            var my2 = SortedTestDeck.Instance.Cards.ToArray();
            CollectionAssert.AreNotEqual(my, my2);
        }
Ejemplo n.º 12
0
 static void Main(string[] args)
 {
     var deck = new Deck();
     deck.PrintDeck();
     deck.Shuffle();
     Console.WriteLine("\nSHUFFLED\n");
     deck.PrintDeck();
     Console.ReadKey();
 }
Ejemplo n.º 13
0
        public void OneDeck_CreateTwoCardsTheSameSuitAndValueOnFullDeck_DeckCardsWillNotBeUnique()
        {
            Deck testdeck = new Deck();
            testdeck.InitializeFullDeck();
            testdeck.Cards.Add(new Card { cardsuit = 1, cardvalue = 3 });

            Assert.AreEqual(testdeck.Cards.Count == 53, true);
            Assert.AreEqual(testdeck.AreCardsUnique(), false);
        }
Ejemplo n.º 14
0
        private void SetUp()
        {
            Deck aDeck = new Deck(new Suit[] {Suit.Clubs, Suit.Diamonds}, 
                new FaceValue[] {FaceValue.King, FaceValue.Queen, FaceValue.Jack, FaceValue.Ten});

            aDeck.Shuffle();
            m_Hand1 = new Hand();
            m_Hand2 = new Hand();
            aDeck.Deal(new Hand[]{m_Hand1, m_Hand2});
            ShowHand(panel1, m_Hand1);
            ShowHand(panel2, m_Hand2);
        }
Ejemplo n.º 15
0
        public void Test_Constructor_SetsFiftyTwoCardsInAList()
        {
            //Arrange
            int expected = 52;
            Mock<DeckGenerator> mockGenerateDeck = new Mock<DeckGenerator>();

            //Act
            Deck testDeck = new Deck(mockGenerateDeck.Object.GenerateDeck());

            //Assert
            Assert.AreEqual(expected, testDeck.listOfCards.Count);
        }
Ejemplo n.º 16
0
        public void Test_TakeRandomCard_ReturnsACardAndRemovesItFromTheDeck()
        {
            //Arrange
            Mock<DeckGenerator> mockGenerateDeck = new Mock<DeckGenerator>();
            Deck testDeck = new Deck(mockGenerateDeck.Object.GenerateDeck());
            int expectedNumber = 51;

            //Act
            Card returnedCard = testDeck.TakeRandomCard();

            //Assert
            Assert.IsInstanceOfType(returnedCard, typeof(Card));
        }
Ejemplo n.º 17
0
        public void Test_TakeTopCard_ReturnsFirstCardAndRemovesItFromTheDeck()
        {
            //Arrange
            Mock<DeckGenerator> mockGenerateDeck = new Mock<DeckGenerator>();
            Deck testDeck = new Deck(mockGenerateDeck.Object.GenerateDeck());
            Card expectedCard = testDeck.listOfCards.First();
            int expectedNumber = 51;

            //Act
            Card returnedCard = testDeck.TakeTopCard();

            //Assert
            Assert.AreEqual(expectedCard, returnedCard);
            Assert.AreEqual(expectedNumber, testDeck.listOfCards.Count);
        }
Ejemplo n.º 18
0
        private void button1_Click(object sender, EventArgs e)
        {
            Deck = new Deck();

            pictureBox1.Image = Deck.Cards[0].Image;
        }
Ejemplo n.º 19
0
        public void OneDeck_RemoveACard_CardsWillRemainSorted()
        {
            Deck testdeck = new Deck();
            testdeck.InitializeFullDeck();

            Random rnd = new Random();
            var numOfCards = testdeck.Cards.Count;

            testdeck.Cards.RemoveAt(rnd.Next(numOfCards));
            Assert.AreEqual(testdeck.AreCardsUnique(), true);
            Assert.AreEqual(testdeck.IsSorted(), true);
        }
Ejemplo n.º 20
0
 public void OneDeck_IsItSortedWhenInitialized_WillBeSorted()
 {
     Deck testdeck = new Deck();
     testdeck.InitializeFullDeck();
     Assert.AreEqual(testdeck.IsSorted(), true);
 }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            Deck deck1 = new Deck();
            int k;
            for (int i = 0; i < 2; i++)
            {
                for (int j = 1; j< (6 + 1); j++)
                {
                    deck1.Cards.Add(new Card { cardsuit = i, cardvalue = j });
                }
            }
            if (deck1.IsSorted())
            {
                Console.WriteLine("\nYes the incomplete Deck is Sorted\n");
            }

            for (Card tmpcard = deck1.DealCard(); tmpcard != null; tmpcard = deck1.DealCard())
            {
                Console.Write("drew: a(n)  {0}\n", Card.GetCardName(tmpcard));
            }
            Console.WriteLine("\n\nLet's Shuffle The Deck!\n\n");

            deck1.Shuffle();
            for (Card tmpcard = deck1.DealCard(); tmpcard != null; tmpcard = deck1.DealCard())
            {
                Console.Write("drew: a(n)  {0}\n", Card.GetCardName(tmpcard));
            }

            Console.WriteLine("\nLet's Initialize a full deck\n");
            deck1.InitializeFullDeck();

            bool tmp = deck1.AreCardsUnique();
            if (tmp && deck1.Cards.Count() == 52)
                Console.WriteLine("We have 52 card and no duplicates - we have an official set!\n\n");

            for (Card tmpcard = deck1.DealCard(); tmpcard != null; tmpcard = deck1.DealCard())
            {
                Console.Write("drew: a(n)  {0}\n", Card.GetCardName(tmpcard));
            }

            Console.WriteLine("\n\nLet's Shuffle The Deck!\n\n");

            deck1.Shuffle();

            if (!deck1.IsSorted())
            {
                Console.WriteLine("\nThe Deck is not Sorted\n");
            }

            k = 1;

            foreach (var card in deck1.Cards)
                Console.WriteLine("({0}) drew a {1}", k++, Card.GetCardName(card));

            Console.WriteLine("\n\nLet's Sort The Deck!\n\n");

            deck1.Sort();

            if (deck1.IsSorted())
            {
                Console.WriteLine("\nYes the Deck is Sorted\n");
            }

            k = 1;

            foreach (var card in deck1.Cards)
                Console.WriteLine("({0}) drew a(n) {1}", k++, Card.GetCardName(card));

            Console.ReadLine();
        }
Ejemplo n.º 22
0
 public Card Draw(Deck cards)
 {
     hand.Add(cards.Deal());
     return(hand[0]);
 }
        public void OneDeck_DeckContains52Cards_IsTrue()
        {
            Deck testdeck = new Deck();

            Assert.AreEqual(testdeck.TupCards.Count, 52);
        }
Ejemplo n.º 24
0
        public void TwoDeck_ShuffleOneSortOther_BothHaveKeptState()
        {
            Deck testdeck = new Deck();
            Deck testdeck2 = new Deck();

            testdeck.InitializeFullDeck();
            testdeck2.InitializeFullDeck();

            testdeck.Shuffle();
            testdeck.Sort();
            testdeck2.Shuffle();

            Assert.AreEqual(testdeck.IsSorted(), true);
            Assert.AreEqual(testdeck2.IsSorted(), false);
        }
 static void Main(string[] args)
 {
     Deck myDeck = new Deck();
     Console.WriteLine("Before Shuffle: ");
     myDeck.showCards();
     Console.WriteLine("*****************");
     Console.ReadKey();
     myDeck.shuffle();
     Console.WriteLine("After Shuffle: ");
     myDeck.showCards();
     Console.ReadKey();
 }
Ejemplo n.º 26
0
 public void OneDeck_ShuffledThenSorted_WillBeSorted()
 {
     Deck testdeck = new Deck();
     testdeck.InitializeFullDeck();
     testdeck.Shuffle();
     testdeck.Sort();
     Assert.AreEqual(testdeck.IsSorted(), true);
 }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            Console.TreatControlCAsInput = false;
            Console.WriteLine("Welcome to DeckOfCards game");
            Console.WriteLine("Press Enter to proceed.....");

            if (Console.ReadKey().Key == ConsoleKey.Enter)
            {
                Console.WriteLine("Enter to Name of Player");
                string playerName = Console.ReadLine();
                Player player     = new Player(playerName); // Creates Player object with the player name

                Console.WriteLine("Press Ctrl-c to exit the game");
                Game game        = new Game(player);      //Creates Game object which starts the game.
                Deck deckOfcards = game.GetDeckOfcards(); // get cards
                Console.WriteLine(game.GreetPlayer());

                //Console.WriteLine("You have three options below : ");
                Console.WriteLine("Please select any valid option : ");
                Console.WriteLine("1. Play a card");
                Console.WriteLine("2. Shuffle the deck");
                Console.WriteLine("3. Restart the game");

                while (true)
                {
                    string optionValue = Console.ReadLine(); //Reading Option input from User
                    int    option      = 0;
                    try
                    {
                        option = Convert.ToInt32(optionValue);
                    }
                    catch {
                        Console.WriteLine("Please provide valid option");
                        throw;
                    }

                    if (option == 1)
                    {
                        Console.WriteLine(deckOfcards.PlayACard()); //Gives the top card on the deck of cards.
                    }
                    else if (option == 2)
                    {
                        deckOfcards.ShuffleCards(); // Shuffle the cards
                        Console.WriteLine("Cards are well Shuffled");
                    }
                    else if (option == 3)
                    {
                        deckOfcards.RestartTheGame(); //Restart the game
                        Console.WriteLine("Started a new Game");
                    }
                    else if (option == 4)
                    {
                        Console.WriteLine(deckOfcards.NoOfCardsLeft()); // No of left in the game
                    }
                    else
                    {
                        Console.WriteLine("Select a valid option");
                    }
                }
            }
        }