Exemple #1
0
        /// <summary>
        /// Event handler for the image card mouse move event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseEventArgs"/> instance containing the event data.</param>
        private void ImgCardMouseMove(object sender, MouseEventArgs e)
        {
            if (isDrag)
            {
                Point newMousePos = e.GetPosition(LayoutRoot);

                double dx = newMousePos.X - oldMousePos.X;
                double dy = newMousePos.Y - oldMousePos.Y;

                GameShape gameShape = GameShape.GetGameShape(this.Card.Deck.Game);

                for (int i = this.Card.Deck.Cards.IndexOf(this.Card); i < this.Card.Deck.Cards.Count; i++)
                {
                    CardShape cardShape = gameShape.GetCardShape(this.Card.Deck.Cards[i]);
                    Canvas.SetLeft(cardShape, Canvas.GetLeft(cardShape) + dx);
                    Canvas.SetTop(cardShape, Canvas.GetTop(cardShape) + dy);
                    Canvas.SetZIndex(gameShape.GetDeckShape(this.Card.Deck), 100);
                }
            }

            if (CardMouseMove != null)
            {
                CardMouseMove(this, e);
            }
        }
Exemple #2
0
        /// <summary>
        /// Recalculate all the card positions and animate them to the new positions
        /// Should be called when the deck change its cards order or count
        /// </summary>
        public void UpdateCardShapes()
        {
            GameShape game = GameShape.GetGameShape(Deck.Game);

            NextCardX = 0;
            NextCardY = 0;

            double localCardSpacerX = CardSpacerX;
            double localCardSpacerY = CardSpacerY;

            if ((MaxCardsSpace > 0) && (Deck.Cards.Count > MaxCardsSpace))
            {
                //override the spacers values to squeez cards
                localCardSpacerX = (CardSpacerX * MaxCardsSpace) / Deck.Cards.Count;
                localCardSpacerY = (CardSpacerY * MaxCardsSpace) / Deck.Cards.Count;
            }

            ////Create the animation to move the card from one deck to the other
            Duration duration = new Duration(TimeSpan.FromSeconds(0.2));

            Storyboard sb = new Storyboard();

            sb.Duration = duration;

            //Loop on the Deck Cards (not playing cards)
            for (int i = 0; i < Deck.Cards.Count; i++)
            {
                //Get the card shape
                CardShape cardShape = game.GetCardShape(Deck.Cards[i]);
                if (cardShape.Parent != this.LayoutRoot)
                {
                    LayoutRoot.Children.Add(cardShape);
                }

                // set left and top values
                if (double.IsNaN(Canvas.GetLeft(cardShape)))
                {
                    cardShape.SetValue(Canvas.LeftProperty, Convert.ToDouble(0));
                }
                if (double.IsNaN(Canvas.GetTop(cardShape)))
                {
                    cardShape.SetValue(Canvas.TopProperty, Convert.ToDouble(0));
                }

                //Animate card to its correct position
                DoubleAnimation xAnim = new DoubleAnimation();
                xAnim.Duration = duration;
                sb.Children.Add(xAnim);
                Storyboard.SetTarget(xAnim, cardShape);
                Storyboard.SetTargetProperty(xAnim, new PropertyPath("(Canvas.Left)"));
                xAnim.To = NextCardX;

                DoubleAnimation yAnim = new DoubleAnimation();
                yAnim.Duration = duration;
                sb.Children.Add(yAnim);
                Storyboard.SetTarget(yAnim, cardShape);
                Storyboard.SetTargetProperty(yAnim, new PropertyPath("(Canvas.Top)"));
                yAnim.To = NextCardY;

                Canvas.SetZIndex(cardShape, i);

                //Increment the next card position
                NextCardX += localCardSpacerX;
                NextCardY += localCardSpacerY;
            }

            if (LayoutRoot.Resources.Contains("sb"))
            {
                LayoutRoot.Resources.Remove("sb");
            }

            LayoutRoot.Resources.Add("sb", sb);
            sb.Begin();
        }