public void TestDealCard()
        {
            DeckOfCards deck     = new DeckOfCards();
            int         deckSize = 52;

            foreach (Card testCard in this.completeDeck)
            {
                Card c = deck.DealCard();

                Assert.AreEqual(testCard, c);
                Assert.AreEqual(deckSize--, deck.DeckSize());
            }
            Assert.IsTrue(deckSize == 0);

            bool fail = true;

            try
            {
                Card c = deck.DealCard();
            }
            catch (ArgumentOutOfRangeException drop)
            {
                fail = false;
            }
            finally
            {
                Assert.IsFalse(fail);
            }
        }
Exemplo n.º 2
0
        public void two_dealt_cards_should_never_be_the_same()
        {
            var deck = new DeckOfCards();
            var card1 = deck.DealCard();

            deck.Cards.Count.ShouldEqual(51);

            var card2 = deck.DealCard();

            card1.ShouldNotEqual(card2);
        }
Exemplo n.º 3
0
    public static void Main()
    {
        DeckOfCards myDeck = new DeckOfCards(); // Create an instanciated DeckOfCards object

        myDeck.Shuffle();                       // Place cards in random order

        /* Print all 52 cards in the order in which they are dealt  */
        for (int i = 0; i < 13; i++)
        {
            Console.WriteLine("{0,-20}{1,-20}{2,-20}{3,-20}",
                              myDeck.DealCard(), myDeck.DealCard(), myDeck.DealCard(), myDeck.DealCard());
        }// end for

        Console.ReadLine();
    } // end Main
Exemplo n.º 4
0
        private void ComputerAI(object sender, EventArgs e)
        {
            shuffledLabel.Content       = "";
            computerResultLabel.Content = "";
            playerResultLabel.Content   = "";
            Card card = _computerDeck.DealCard();

            if (card == null)
            {
                EndGame();
                computerActiveCardCanvas.Children.Clear();
            }
            else
            {
                string cardName = card.Face + card.Suit;
                try
                {
                    DrawCardOnCanvas(computerActiveCardCanvas, cardName);
                }
                catch (FileNotFoundException exc)
                {
                    MessageBox.Show(exc.Message, "File not found", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                computerCardLabel.Content       = card.ToString();
                computerCardNumberLabel.Content = "Card #" + (_computerDeck.CurrentCard + 1);

                dealButton.IsEnabled          = true;
                playerCardCanvas.IsEnabled    = true;
                playerCardLabel.Content       = "";
                playerCardNumberLabel.Content = "";
            }

            playerActiveCardCanvas.Children.Clear();
            _computerPlayTimer.Stop();
        }
Exemplo n.º 5
0
        private void DealCard(object sender, EventArgs e)
        {
            Card card = _playerDeck.DealCard();

            string cardName = card.Face + card.Suit;

            try
            {
                DrawCardOnCanvas(playerActiveCardCanvas, cardName);
            }
            catch (FileNotFoundException exc)
            {
                MessageBox.Show(exc.Message, "File not found", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            playerCardLabel.Content       = card.ToString();
            playerCardNumberLabel.Content = "Card #" + (_playerDeck.CurrentCard + 1);

            dealButton.IsEnabled       = false;
            playerCardCanvas.IsEnabled = false;
            CheckWinner();

            if (!_gameOver)
            {
                _computerPlayTimer.Start();
            }
        }
Exemplo n.º 6
0
 private static void Deal13SetsOf4(DeckOfCards deckOfCards)
 {
     for (var set = 0; set < 4; set++)
     {
         for (var hour = 0; hour < 13; hour++)
         {
             FaceDownCards[set, hour] = deckOfCards.DealCard();
         }
     }
 }
Exemplo n.º 7
0
        private static void Main()
        {
            var deckOfCards = new DeckOfCards();

            deckOfCards.Shuffle();
            for (var i = 0; i < 52; i++)
            {
                Console.Write($"{deckOfCards.DealCard(),-19}");
                if ((i + 1) % 4 == 0)
                {
                    Console.WriteLine();
                }
            }
            Console.ReadKey();
        }
        public ActionResult Index()
        {
            DeckOfCards newDeck = new DeckOfCards();
            newDeck.Shuffle();
            StringBuilder handString = new StringBuilder();
            List<card> pokerHand = new List<card>();
            for (int i = 0; i < 5; i++)
            {
                card newCard = newDeck.DealCard();
                handString.Append(newCard.ToString());
                pokerHand.Add(newCard);
            }
            ViewBag.pair = hasPair(pokerHand);
            ViewBag.pokerHand = handString.ToString();

            return View();
        }
Exemplo n.º 9
0
    // execute application
    public static void Main(string[] args)
    {
        DeckOfCards myDeckOfCards = new DeckOfCards();

        myDeckOfCards.Shuffle(); // place Cards in random order

        // display all 52 Cards in the order in which they are dealt
        for (int i = 0; i < 52; ++i)
        {
            Console.Write("{0,-19}", myDeckOfCards.DealCard());

            if ((i + 1) % 4 == 0)
            {
                Console.WriteLine();
            }
        } // end for
    }     // end Main
Exemplo n.º 10
0
    // execute app
    static void Main()
    {
        var myDeckOfCards = new DeckOfCards();

        myDeckOfCards.Shuffle(); // place Cards in random order

        // display all 52 Cards in the order in which they are dealt
        for (var i = 0; i < 52; ++i)
        {
            Console.Write($"{myDeckOfCards.DealCard(),-19}");

            if ((i + 1) % 4 == 0)
            {
                Console.WriteLine();
            }
        }
    }