Exemplo n.º 1
0
        public void SelectStack(CardStack stack)
        {
            if (stack.Count > 0)
            {
                _currentAction = CardAction.Moving;
                int top = stack.GetTopOfSequentialRun();
                _cardsInAction = stack.GetCards();
                _cardsInAction.RemoveRange(0, top);

                _currentStack = stack.Index;
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 3
0
        public void FixupCardHighlights()
        {
            if (_cardsInAction != null && _currentAction != CardAction.None)
            {
                for (int i = 0; i < Board.StackCount; i++)
                {
                    CardStack stack = _board.GetStack(i);
                    foreach (Card card in stack.GetCards())
                    {
                        card.View.Highlighted = false;
                    }
                    foreach (Card cardInAction in _cardsInAction)
                    {
                        if (_board.CanMoveCardToStack(cardInAction, stack))
                        {
                            if (stack.Count > 0)
                            {
                                stack.GetLastCard().View.Highlighted = true;
                            }
                            break;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < Board.StackCount; i++)
                {
                    CardStack stack = _board.GetStack(i);
                    foreach (Card card in stack.GetCards())
                    {
                        card.View.Highlighted = true;
                    }
                }
            }

            // For now, ensure that all completed cards are highlighted
            for (int i = 0; i < _board.CompletedCount(); i++)
            {
                Card completedCard = _board.GetCompletedStack(i);
                completedCard.View.Highlighted = true;
            }
        }
Exemplo n.º 4
0
        public void StartDrag(Point pt)
        {
            CardStack cardStack = GetStackAtPoint(pt);

            if (cardStack != null && cardStack.Count > 0 &&
                (_currentAction == CardAction.None || _currentAction == CardAction.Moving))
            {
                _dragInfo = new DragInfo();

                int top = cardStack.GetTopOfSequentialRun();
                _dragInfo.CardsToDrag = cardStack.GetCards();
                _dragInfo.CardsToDrag.RemoveRange(0, top);

                _dragInfo.Stack = cardStack.Index;

                Point cardOrigin = GetLocationOfCardInStack(cardStack, cardStack.Count - _dragInfo.CardsToDrag.Count);
                _dragInfo.StartPos = pt;
                _dragInfo.Offset   = new Point(_dragInfo.StartPos.X - cardOrigin.X, _dragInfo.StartPos.Y - cardOrigin.Y);
            }
        }