Пример #1
0
        public StackCollapseAnimation(Board board, int stack, List <CardAnimationView> expandedCards)
        {
            _board = board;

            _startTime = DateTime.Now;

            var cardSize  = board.View.GetCardSize();
            int stackBase = board.GetStack(stack).Count - expandedCards.Count;

            _cardAnimations = new List <CardAnimationView>(expandedCards.Count);
            for (int i = 0; i < expandedCards.Count; i++)
            {
                var card = expandedCards[i].Card;
                card.View.Animating = true;

                var destPoint = board.View.GetLocationOfCardInStack(board.GetStack(stack), i + stackBase);

                var animation = new CardAnimationView(card, 0, Duration, expandedCards[i].CurrentRect.Location,
                                                      destPoint, cardSize.X, cardSize.Y);
                _cardAnimations.Add(animation);
            }

            _stopTime = DateTime.Now.AddSeconds(Duration);
            UpdateCardAnimations();
        }
Пример #2
0
        public StackExpandAnimation(Board board, CardStack stack, Point ptExpand)
        {
            _board = board;

            _startTime = DateTime.Now;

            var cardsInStack = stack.GetCards();
            int top          = stack.GetTopOfSequentialRun();

            cardsInStack.RemoveRange(0, top);

            int rows = (cardsInStack.Count + (CardsPerRow - 1)) / CardsPerRow;
            int cols = (cardsInStack.Count < CardsPerRow ? cardsInStack.Count : CardsPerRow);

            var bounds   = board.View.GetViewArea();
            var cardSize = board.View.GetCardSize();
            int spacing  = (bounds.Width - cardSize.X * CardsPerRow) / (CardsPerRow - 1);

            spacing = Math.Min(spacing, 10);

            int xAnchor = ptExpand.X - cols / 2 * cardSize.X - (cols - 1) / 2 * spacing;

            xAnchor = Math.Max(xAnchor, 0);                                                       // Left edge collision
            xAnchor = Math.Min(xAnchor, bounds.Width - cardSize.X * cols - spacing * (cols - 1)); // Right edge collision
            int yAnchor = ptExpand.Y - cardSize.Y / 2;

            yAnchor = Math.Max(yAnchor, 0);                                                        // Top edge collision
            yAnchor = Math.Min(yAnchor, bounds.Height - cardSize.Y * rows - spacing * (rows - 1)); // Bottom edge collision

            CardAnimations = new List <CardAnimationView>(cardsInStack.Count);
            for (int i = 0; i < cardsInStack.Count; i++)
            {
                var card = cardsInStack[i];
                card.View.Animating = true;
                var startPoint = board.View.GetLocationOfCardInStack(stack, i + top);

                int row = i / CardsPerRow;
                int col = i % CardsPerRow;

                int x         = xAnchor + (cardSize.X + spacing) * col;
                int y         = yAnchor + (cardSize.Y + spacing) * row;
                var destPoint = new Point(x, y);

                var animation = new CardAnimationView(card, 0, Duration, startPoint, destPoint, cardSize.X, cardSize.Y);
                CardAnimations.Add(animation);
            }

            _stopTime = DateTime.Now.AddSeconds(Duration);
            UpdateCardAnimations();
        }
Пример #3
0
        public DealAnimation(Board board, List <Card> cardsToDeal)
        {
            _board = board;

            _cardAnimations = new List <CardAnimationView>(Board.StackCount);

            // TODO: Revive this rule at some point?

            /*int cardCount = 0;
             * int stacksEmpty = 0;
             * for (int i = 0; i < Board.StackCount; i++)
             * {
             *      int stackSize = board.GetStack(i).Count;
             *      if (stackSize == 0)
             *              stacksEmpty++;
             *      cardCount += stackSize;
             * }
             *
             * if (stacksEmpty > 0 && cardCount >= Board.StackCount)
             * {
             *      string errorMsg = CardResources.Strings.GetString("EmptyStacksDealError");
             *      _board.View.AddError(errorMsg);
             *      return;
             * }*/

            int dealPos = board.CountOfExtraDealingsLeft() - 1;

            const double delay    = 0.1;
            const double duration = 0.2;

            var bounds     = board.View.GetViewArea();
            var cardSize   = board.View.GetCardSize();
            var startPoint = new Point(bounds.Width - cardSize.X - dealPos * 25, bounds.Height - cardSize.Y);

            for (int i = 0; i < cardsToDeal.Count; i++)
            {
                Card cardDealt = cardsToDeal[i];
                cardDealt.Reveal();
                cardDealt.View.Animating = true;

                Point destPoint = board.View.GetLocationOfCardInStack(board.GetStack(i), board.GetStack(i).Count);
                var   animation = new CardAnimationView(cardDealt, i * delay, duration, startPoint, destPoint, cardSize.X,
                                                        cardSize.Y);
                _cardAnimations.Insert(0, animation);
            }

            _stopTime = DateTime.Now.AddSeconds(cardsToDeal.Count * delay + duration);
            UpdateCardAnimations();
        }
Пример #4
0
        public ClearRunAnimation(Board board, int stack, Point destPoint)
        {
            Stack = stack;

            var cardSize  = board.View.GetCardSize();
            int stackSize = board.GetStack(stack).Count;

            _cardAnimations = new List <CardAnimationView>(13);
            for (int i = 0; i < 13; i++)
            {
                int pos  = stackSize - 13 + i;
                var card = board.GetStack(stack).GetCard(pos);
                card.View.Animating = true;
                var startPoint = board.View.GetLocationOfCardInStack(board.GetStack(stack), pos);

                var animation = new CardAnimationView(card, (13 - i) * Delay, Duration, startPoint, destPoint, cardSize.X, cardSize.Y);
                _cardAnimations.Add(animation);
            }

            _stopTime            = DateTime.Now.AddSeconds(13 * Delay + Duration);
            _completedAnimations = new List <CardAnimationView>(13);
            UpdateCardAnimations();
        }