Exemple #1
0
        public CardPack()
        {
            _pack = new List<Card>();
            Uri uri = new Uri("./Images/cards.png", UriKind.Relative);
            source = new BitmapImage(uri);
            _cardFronts = new List<CroppedBitmap>();
            CardBack = new Image();

            int w = source.PixelWidth / 13;
            int h = source.PixelHeight/5;

            for (int s = 0; s < 4; s++)
            {
                for (int v = 0; v < 13; v++)
                {
                    int imageIndex = (s*13) + v;

                    int fx = imageIndex % 13;
                    int fy = imageIndex / 13;

                    Int32Rect sourceRect = new Int32Rect(fx * w, fy * h, w, h);
                    CroppedBitmap front = new CroppedBitmap(source, sourceRect);

                    sourceRect = new Int32Rect(2 * w, 4 * h, w, h);
                    CroppedBitmap back = new CroppedBitmap(source, sourceRect);

                    Image frontImage = new Image {Source = front};
                    Image backImage = new Image { Source = back };

                    Card card = new Card((CardSuit)s, (CardValue)v, frontImage, backImage);
                    _pack.Add(card);
                }
            }
        }
        private void AddToFaceUp(StackPanel panel, Card c)
        {
            int topMargin = 0;
            if (panel.Children.Count > 0) topMargin = -65;
            int leftMargin = panel.Children.Count * 5;

                c.FrontFace.Margin = new Thickness(leftMargin, topMargin, 0, 0);
                c.FrontFace.Height = 70;
                c.FrontFace.Width = 40;
                panel.Children.Add(c.FrontFace);
        }
Exemple #3
0
        /// <summary>
        /// Return the top card from the pack
        /// </summary>
        /// <returns></returns>
        public Card DealCard()
        {
            if (_pack.Count == 0) return null;

            Card c = new Card();
            int i = _pack.Count - 1;
            c = _pack[i];
            _pack.RemoveAt(i);
            return c;
        }
Exemple #4
0
        /// <summary>
        /// Return a random card from the pack
        /// </summary>
        /// <returns></returns>
        public Card DealRandom()
        {
            if (_pack.Count == 0) return null;

            Card c = new Card();
            Random rnd = new Random();
            int i = rnd.Next(_pack.Count);
            c = _pack[i];
            _pack.RemoveAt(i);
            return c;
        }