예제 #1
0
        public PlayingCard DrawCard()
        {
            if (IsEmpty)
            {
                throw new NoDrawException();
            }

            PlayingCard card = _Cards[0];

            _Cards.RemoveAt(0);
            if (_Cards.Count == 0)
            {
                IsEmpty = true;
            }
            return(card);
        }
예제 #2
0
        }                                                     //get current deck

        //create deck of 52 cards : 13 values each , with 4 suits
        public void SetUpDeck()
        {
            int i = 0;

            foreach (SUIT s in Enum.GetValues(typeof(SUIT)))
            {
                foreach (VALUE v in Enum.GetValues(typeof(VALUE)))
                {
                    deck[i] = new PlayingCard {
                        MySuit = s, MyValue = v
                    };
                    i++;
                }
            }
            ShuffleCards();
        }
예제 #3
0
        public void Shuffle()
        {
            int index;

            for (int i = 0; i < 1000; i++)
            {
                // Grab the top card
                PlayingCard card = _Cards[0];
                //remove that card from the deck
                _Cards.RemoveAt(0);
                //randomly generate a value of where to replace the card in the deck
                // values will be 0 to 51
                index = Rnd.Next(_Cards.Count);
                //insert the card in the collection at position index
                //cards in the collection that are beyond the index position will be
                //   pushed down ie  postion index 33 moves current cards 33-51 to be
                //   34 -52
                _Cards.Insert(index, card);
            }
        }
예제 #4
0
        public static void DrawCardsSuitValue(PlayingCard card, int xcoor, int ycoor)
        {
            Console.OutputEncoding = Encoding.Unicode;

            //displays suit and value of the card inside its outline
            string cardSuit = " ";
            int    x        = xcoor * 12 + 45;
            int    y        = ycoor + 2;

            //lista med x och y positioner för innehållet i kortet
            List <int> cx = new List <int>();
            List <int> cy = new List <int>();

            int cv;        //kort value
            int drawCount; //antalet symboler som ska ritas upp, räknar in kortets value också

            // encode each byte array from the CodePage437 into a character
            // hearts and diamonds are red , clubs and spades are black
            switch (card.MySuit)
            {
            case PlayingCard.SUIT.HEARTS:
                cardSuit = Encoding.Unicode.GetString(Encoding.Unicode.GetBytes("\x2665"));
                Console.ForegroundColor = ConsoleColor.Red;
                break;

            case PlayingCard.SUIT.DIAMONDS:
                cardSuit = Encoding.Unicode.GetString(Encoding.Unicode.GetBytes("\x2666"));
                Console.ForegroundColor = ConsoleColor.Red;
                break;

            case PlayingCard.SUIT.CLUBS:
                cardSuit = Encoding.Unicode.GetString(Encoding.Unicode.GetBytes("\x2663"));
                Console.ForegroundColor = ConsoleColor.Black;
                break;

            case PlayingCard.SUIT.SPADES:
                cardSuit = Encoding.Unicode.GetString(Encoding.Unicode.GetBytes("\x2660"));
                Console.ForegroundColor = ConsoleColor.Black;
                break;
            }

            switch (card.MyValue)
            {
            case PlayingCard.VALUE.TWO:
                cv        = 2;      //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 7, 7, 11 });
                cy.AddRange(new int[] { 3, 5, 7, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.THREE:
                cv        = 3;      //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 7, 7, 7, 11 });
                cy.AddRange(new int[] { 3, 5, 6, 7, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.FOUR:
                cv        = 4;      //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 5, 5, 8, 8, 11 });
                cy.AddRange(new int[] { 3, 5, 7, 5, 7, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.FIVE:
                cv        = 5;      //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 5, 5, 7, 9, 9, 11 });
                cy.AddRange(new int[] { 3, 5, 7, 6, 5, 7, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.SIX:
                cv        = 6;      //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 5, 5, 5, 9, 9, 9, 11 });
                cy.AddRange(new int[] { 3, 5, 6, 7, 5, 6, 7, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.SEVEN:
                cv        = 7;      //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 5, 5, 5, 7, 9, 9, 9, 11 });
                cy.AddRange(new int[] { 3, 5, 6, 7, 6, 5, 6, 7, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.EIGHT:
                cv        = 8;      //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 5, 5, 5, 7, 9, 9, 9, 7, 11 });
                cy.AddRange(new int[] { 3, 5, 6, 7, 4, 5, 6, 7, 8, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.NINE:
                cv        = 9;      //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 5, 5, 5, 7, 7, 9, 9, 9, 7, 11 });
                cy.AddRange(new int[] { 3, 5, 6, 7, 4, 6, 5, 6, 7, 8, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.TEN:
                cv        = 10;     //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 5, 5, 5, 7, 7, 7, 9, 9, 9, 7, 11 });
                cy.AddRange(new int[] { 3, 5, 6, 7, 4, 5, 7, 5, 6, 7, 8, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.JACK:
                cv        = 10;     //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 5, 5, 5, 7, 7, 7, 9, 9, 9, 7, 11 });
                cy.AddRange(new int[] { 3, 5, 6, 7, 4, 5, 7, 5, 6, 7, 8, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.QUEEN:
                cv        = 10;     //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 5, 5, 5, 7, 7, 7, 9, 9, 9, 7, 11 });
                cy.AddRange(new int[] { 3, 5, 6, 7, 4, 5, 7, 5, 6, 7, 8, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.KING:
                cv        = 10;     //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 5, 5, 5, 7, 7, 7, 9, 9, 9, 7, 11 });
                cy.AddRange(new int[] { 3, 5, 6, 7, 4, 5, 7, 5, 6, 7, 8, 9 });

                CardLoop();
                break;

            case PlayingCard.VALUE.ACE:
                cv        = 1;      //kort value
                drawCount = cv + 2; //antalet symboler som ska ritas upp, räknar in kortets value också

                //lägger till i cx och cy
                cx.AddRange(new int[] { 3, 7, 11 });
                cy.AddRange(new int[] { 3, 6, 9 });

                CardLoop();
                break;
            }

            //ritar upp innehåll på korten
            void CardLoop()
            {
                for (int i = 0; i < drawCount; i++)
                {
                    Console.SetCursorPosition(x + cx[i], y + cy[i]);

                    if (i == 0 || i == drawCount - 1)
                    {
                        switch (card.MyValue)
                        {
                        case PlayingCard.VALUE.JACK:
                            Console.Write('J');
                            break;

                        case PlayingCard.VALUE.QUEEN:
                            Console.Write('Q');
                            break;

                        case PlayingCard.VALUE.KING:
                            Console.Write('K');
                            break;

                        case PlayingCard.VALUE.ACE:
                            Console.Write('A');
                            break;

                        default:
                            Console.Write(cv);
                            break;
                        }
                    }
                    else
                    {
                        Console.Write(cardSuit);
                    }
                }
            }
        }