Example #1
0
        public CardGame()
        {
            PlayerHands = new List <Hand>();
            var standardDeck = new StandardDeck();

            SetDeck(standardDeck);
        }
        public static List <Card> GetCardsFromDeck(string deckName)
        {
            Deck deck = decks.Find(x => x.Name == deckName);

            try
            {
                switch (deck.Type)
                {
                case "Commander":
                    CommanderDeck commanderDeck = deck as CommanderDeck;
                    return(commanderDeck.Cards);

                case "Standard":
                    StandardDeck standardDeck = deck as StandardDeck;
                    return(standardDeck.Cards);

                case "Extras":
                    ExtraCards extraCards = deck as ExtraCards;
                    return(extraCards.Cards);
                }
            }
            catch (Exception e)
            {
                //implement error handling
                Console.WriteLine("something went wrong and the deck could not be opened." + e.Message);
            }

            return(null);
        }
Example #3
0
        public void LoadCards()
        {
            //var test = LoadFile("BackRed");
            //test = LoadFile("BackBlack");

            BackRed   = (MarkupString)$"<object class='playing-card' type='image/svg+xml' data='images/cards/BackRed.svg'></object>";
            BackBlack = (MarkupString)$"<object class='playing-card' type='image/svg+xml' data='images/cards/BackBlack.svg'></object>";

            var deck = new StandardDeck();
            int i    = 0;

            Faces        = new MarkupString[deck.Suits * deck.Ranks];
            FacesAsImage = new MarkupString[deck.Suits * deck.Ranks];
            foreach (var suit in deck.SuitDescriptions)
            {
                foreach (var rank in deck.RankDescriptions)
                {
                    //test = LoadFile($"{rank}{suit}");

                    // Embeded SVG too large, sends cards too often
                    //Faces[i++] = LoadFile($"{rank}{suit}");

                    // Send the SVG as an object so it can be cached
                    Faces[i] = (MarkupString)$"<object class='playing-card' type='image/svg+xml' data='images/cards/{rank}{suit}.svg'></object>";

                    // Send the SVG as an image so it can be cached (Note: sending as an image works, but does not rotate and scale like an SVG should
                    FacesAsImage[i] = (MarkupString)$"<img class='playing-card' src='images/cards/{rank}{suit}.svg'>";
                    i++;
                }
            }
        }
        public void StandardDeckProviderCreatesADeck()
        {
            StandardDeck deck = StandardDeckProvider.Create();

            Assert.NotNull(deck);
            Assert.True(deck.Cards.Any());
            Assert.True(deck.Cards.Count == 54); // 52 + jokers
        }
Example #5
0
    public void StandardDeckTest()
    {
        var objectUnderTest = new PointsCalculator();
        var entireDeck      = new StandardDeck();
        var result          = objectUnderTest.GetPoints(entireDeck.Cards.Cards);

        Assert.True(result == 96);
    }
Example #6
0
        public void TestStandardDeckSize()
        {
            var expectedDeckSize   = 52;
            var expectedSuitNumber = 4;
            var deck = new StandardDeck();

            Assert.IsTrue(deck.Cards.Count == expectedDeckSize);
            Assert.IsTrue(deck.Cards.Where(card => card.Suit == CardSuit.Club).Count() == expectedDeckSize / expectedSuitNumber);
        }
Example #7
0
        public void TestHighCardHandOutcomes(HighCardTestHand testHand)
        {
            var standardDeck = new StandardDeck();
            var highCardGame = new HighCard();

            var playerHand  = HighCardTestHand.GetPlayerHand(testHand.PlayerHand, standardDeck);
            var oponentHand = HighCardTestHand.GetPlayerHand(testHand.OpponentHand, standardDeck);

            Assert.AreEqual(testHand.HandOutcome, highCardGame.GetHandOutcome(playerHand, oponentHand));
        }
Example #8
0
        public void TestBlackjackHandOutcomes(BlackJackTestHand testHand)
        {
            var standardDeck  = new StandardDeck();
            var blackJackGame = new Blackjack();

            var playerHand  = BlackJackTestHand.GetPlayerHand(testHand.PlayerHand, standardDeck);
            var oponentHand = BlackJackTestHand.GetPlayerHand(testHand.OpponentHand, standardDeck);

            Assert.AreEqual(testHand.HandOutcome, blackJackGame.GetHandOutcome(playerHand, oponentHand));
        }
        public void Can_Cut_Cards()
        {
            var sut = new StandardDeck();

            sut.Cut(100);

            All_Cards_Are_Unique();

            Assert.AreEqual(52, sut.Cards.Count);
        }
Example #10
0
            public static Hand GetPlayerHand(List <CardName> cardNames, StandardDeck deck)
            {
                var hand = new Hand();

                foreach (var cardName in cardNames)
                {
                    hand.Cards.Add(deck.Cards.First(c => c.Name == cardName));
                }

                return(hand);
            }
Example #11
0
        public void Init()
        {
            _standardDeck  = new StandardDeck();
            _fullDeckCount = _standardDeck.CurrentCardCount();

            for (var i = 0; i < 10; i++)
            {
                _standardDeck.DrawCard();
            }

            _standardDeck.RefeshDeck();
        }
        public void Utility()
        {
            var sut = new StandardDeck();

            var cards = sut.Cards;

            _dumpToConsole(cards);

            sut.Cut();

            _dumpToConsole(cards);
        }
        public void Deck_Has_N_Cards(int deckCount, int expectedCardCount)
        {
            var sut = new StandardDeck(deckCount);

            var cards = sut.Cards;

            Assert.AreEqual(expectedCardCount, cards.Count);

            //we should have n-number of any particular card
            var queenOfHearts = cards.Where(x => x.Rank.Name == StandardRank.Queen && x.Suit == StandardSuit.Hearts);

            Assert.AreEqual(deckCount, queenOfHearts.Count());
        }
Example #14
0
        public void StandardDeckTest_CreateNewDeckShouldSucceed()
        {
            StandardDeck actualCards   = new StandardDeck();
            List <Card>  expectedCards = TestHelper.CreatedSortedStandardDeck();

            actualCards.CreateNewDeck();

            Assert.AreEqual(expectedCards.Count, actualCards.Deck.Count);

            for (int i = 0; i < expectedCards.Count; i++)
            {
                Assert.AreEqual(expectedCards[i].Suit, actualCards.Deck[i].Suit);
                Assert.AreEqual(expectedCards[i].Value, actualCards.Deck[i].Value);
                Assert.AreEqual(expectedCards[i].SortedOrder, actualCards.Deck[i].SortedOrder);
            }
        }
    public void ShuffleTestForFullDeck()
    {
        HashSet <string> allStates = new HashSet <string>();
        var objectUnderTest        = new StandardDeck().Cards;
        var initialState           = CardPileRepresentation(objectUnderTest);

        allStates.Add(initialState);
        int numberOfShuffles = 1000;

        for (int i = 0; i < numberOfShuffles; i++)
        {
            objectUnderTest.Shuffle();
            allStates.Add(CardPileRepresentation(objectUnderTest));
        }

        //make sure that we never ever see the deck in a state we've seen before after we shuffle
        Assert.True(allStates.Count == numberOfShuffles + 1);
    }
Example #16
0
    public void TestStandardDeck()
    {
        var deck = new StandardDeck();

        Assert.True(deck.Cards.Cards.Count == 52);
        foreach (var suit in new List <string> {
            Constants.Suits.Clubs, Constants.Suits.Diamonds, Constants.Suits.Hearts, Constants.Suits.Spades
        })
        {
            Assert.True(deck.Cards.Cards.Where(item => item.Suit == suit).Count() == 13);
        }
        foreach (var rank in new List <string> {
            "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"
        })
        {
            Assert.True(deck.Cards.Cards.Where(item => item.Rank == rank).Count() == 4);
        }
    }
        public void Can_Draw_A_Card()
        {
            var sut = new StandardDeck();

            Assert.DoesNotThrow(() =>
            {
                var card = sut.Draw();

                Assert.IsNotNull(card);
            });

            var cardCount = sut.Cards.Count;

            for (var i = 0; i < cardCount; i++)
            {
                sut.Draw();
            }

            Assert.Throws <InvalidOperationException>(() => { sut.Draw(); });
        }
        public static Deck CreateDeck(string name, string type)
        {
            switch (type)
            {
            case "Commander":
                CommanderDeck commander = new CommanderDeck(name, type);
                return(commander);

            case "Standard":
                StandardDeck standard = new StandardDeck(name, type);
                return(standard);

            case "Extras":
                ExtraCards extras = new ExtraCards(name, type);
                return(extras);

            default:
                //Implement error handling
                return(null);
            }
        }
        /// <summary>
        /// CardDealer constructor which can take a deck of cards and a windows form
        /// </summary>
        /// <param name="deck">Default = null</param>
        /// <param name="form">Default = null</param>
        public CardDealer(StandardDeck deck = null, Form form = null)
        {
            MyDeck = deck;                                                                                                                                //set MyDeck based on entered deck

            Shuffle();                                                                                                                                    //shuffle the deck

            if (form != null)                                                                                                                             //check if form is null
            {
                MyDeck.DeckImage.MyCard.FaceUp = false;                                                                                                   //flip deck image to become a card back
                MyDeck.DeckImage.UpdateCardImage();                                                                                                       //update deck image

                MyDeck.DeckImage.Location = new Point((form.Width - (MyDeck.DeckImage.Width + 40)), ((form.Height / 2) - (MyDeck.DeckImage.Height / 2))); //set the deck image location to middle right of form

                form.Invoke((MethodInvoker) delegate                                                                                                      //use the Invoke method to safely alter a control of the ui thread
                {
                    form.Controls.Add(MyDeck.DeckImage);                                                                                                  //add the deckImage control to the form
                });

                SoundPlayer audio = new SoundPlayer(CardGameLibrary.Properties.Resources.contact_sound); //create new soundplayer for the contact_sound
                audio.PlaySync();                                                                        //play the contact_sound haulting program
            }
        }
Example #20
0
        //gives value to the cards (numbers and the suits)
        public IDeck CreateDeck()
        {
            var deck = new StandardDeck
            {
                Cards = new List <Card>(StandardDeck.NumCards)
            };

            foreach (Card.Values value in Enum.GetValues(typeof(Card.Values)))
            {
                foreach (Card.Suits suit in Enum.GetValues(typeof(Card.Suits)))
                {
                    var card = new Card
                    {
                        Value = value,
                        Suit  = suit
                    };
                    deck.Cards.Add(card);
                }
            }

            return(deck);
        }
Example #21
0
        internal static CardMask[] GenerateStandardDeckCardMaskTable()
        {
            var deck = new StandardDeck();
            var cardMaskTable = new CardMask[deck.NoOfCards];

            for (var cardIndex = 0; cardIndex != deck.NoOfCards; ++cardIndex)
            {
                var cardSuit = deck.ToSuit(deck.ToSuitIndex(cardIndex));
                var cardRankIndex = deck.ToRankIndex(cardIndex);
                CardMask cardMask;

                switch (cardSuit)
                {
                    case CardSuit.Hearts:
                        cardMask = (CardMask)((0x1L << cardRankIndex) << 48);
                        break;
                    case CardSuit.Diamonds:
                        cardMask = (CardMask)((0x1L << cardRankIndex) << 32);
                        break;
                    case CardSuit.Clubs:
                        cardMask = (CardMask)((0x1L << cardRankIndex) << 16);
                        break;
                    case CardSuit.Spades:
                        cardMask = (CardMask)(0x1L << cardRankIndex);
                        break;
                    case CardSuit.Undefined:
                        cardMask = CardMask.Empty;
                        break;
                    default:
                        cardMask = CardMask.Empty;
                        break;
                }

                cardMaskTable[cardIndex] = cardMask;
            }

            return cardMaskTable;
        }
        public static void AddCardToDeck(Deck deck, Card card)
        {
            switch (deck.Type)
            {
            case "Commander":
                CommanderDeck commanderDeck = deck as CommanderDeck;
                commanderDeck.AddCard(card);
                return;

            case "Standard":
                StandardDeck standardDeck = deck as StandardDeck;
                standardDeck.AddCard(card);
                return;

            case "Extras":
                ExtraCards extraCards = deck as ExtraCards;
                extraCards.AddCard(card);
                return;

            default:
                //Handle Error
                return;
            }
        }
        public void All_Cards_Are_Unique()
        {
            var sut = new StandardDeck();

            var cards = sut.Cards;

            var hashes = new Dictionary <int, ICard>();

            foreach (var card in cards)
            {
                var hash = card.GetHashCode();

                if (hashes.ContainsKey(hash))
                {
                    throw new Exception($"{card.Rank} {card.Suit} has already been added to this list!");
                }
                else
                {
                    hashes.Add(hash, card);
                }
            }

            Assert.AreEqual(52, hashes.Count);
        }
Example #24
0
        public static void Main(string[] args)
        {
            SetUpConsoleSettings();

            // North
            // West
            // South
            // East

            var deck     = new StandardDeck();
            int handSize = deck.Count / 4;
            var card     = deck.Pull();
            var card2    = deck.Pull();
            var card3    = deck.Pull();
            var card4    = deck.Pull();

            DrawCard(1, 1, card, CardStatus.Selected);
            DrawCard(7, 1, card2, CardStatus.Disabled);
            DrawCard(13, 1, card3);
            DrawCard(19, 1, card4);
            DrawCardBack(1, 5);
            DrawCardBack(7, 5);
            DrawCardBack(13, 5);
            DrawCardBack(19, 5);
            DrawCardBack(25, 5);
            // If the OS is windows -> remove scrollbars, disable maximizing and resizing

            /*var north = new Player(Console.WindowWidth / 2 - (handSize * (UIConstants.Card.Width + 1) / 2) - 1, 1);
             * var south = new Player(Console.WindowWidth / 2 - (handSize * (UIConstants.Card.Width + 1) / 2) - 1, Console.WindowHeight - 4);
             * var west = new Player(3, Console.WindowHeight / 2 - 3);
             * var east = new Player(Console.WindowWidth - 4 * (UIConstants.Card.Width + 2), Console.WindowHeight / 2 - 3);
             *
             * //Console.Clear();
             *
             * for (int i = 0; i < handSize; i++)
             * {
             *  var card = deck.Pull();
             *  north.Hand.Add(card);
             *  DrawCard(north.X, north.Y, card);
             *  north.X += UIConstants.Card.Width + 1;
             * }
             *
             * for (int i = 0; i < handSize; i++)
             * {
             *  var card = deck.Pull();
             *  south.Hand.Add(card);
             *  DrawCard(south.X, south.Y, card);
             *  south.X += UIConstants.Card.Width + 1;
             * }
             *
             * for (int i = 0; i < handSize; i++)
             * {
             *  var card = deck.Pull();
             *  west.Hand.Add(card);
             *  DrawCard(west.X, west.Y, card);
             *  west.X += UIConstants.Card.Width + 1;
             *
             *  if (i == 3)
             *  {
             *      west.X = 3;
             *      west.Y += 4;
             *  }
             * }
             *
             * for (int i = 0; i < handSize; i++)
             * {
             *  var card = deck.Pull();
             *  east.Hand.Add(card);
             *  DrawCard(east.X, east.Y, card);
             *  east.X += UIConstants.Card.Width + 1;
             *
             *  if (i == 3)
             *  {
             *      east.X = Console.WindowWidth - 4 * (UIConstants.Card.Width + 2);
             *      east.Y += 4;
             *  }
             * }*/

            Console.ReadLine();
        }