Esempio n. 1
0
        public void SwapCards(Common.Card first, Common.Card second)
        {
            Contract.Requires(first != null);
            Contract.Requires(second != null);
            Contract.Requires(Contract.Exists(_cardGraphics.Keys, x => x == first));
            Contract.Requires(Contract.Exists(_cardGraphics.Keys, x => x == second));

            DevCard.SwapPositions(_cardGraphics[first], _cardGraphics[second]);

            // Swap the drawing order as well so the new player card is not drawn above the other player cards.
            var indexOfFirstCard  = _drawingOrder.IndexOf(first);
            var indexOfSecondCard = _drawingOrder.IndexOf(second);

            _drawingOrder[indexOfFirstCard]  = second;
            _drawingOrder[indexOfSecondCard] = first;
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a card to the middle for the current trick. The card will be drawn above any other cards in the middle.
        /// </summary>
        /// <param name="playerPosition">The position of the player who dealt the card.</param>
        /// <param name="card">The card to be played.</param>
        public void AddCardToMiddle(int playerPosition, Common.Card card)
        {
            var centerPosition = new Vector2(400, 180);

            // Place the player cards in a circle around the middle
            int xFactor = 0;
            int yFactor = 0;

            switch (playerPosition)
            {
            case 0:
                xFactor = 0;
                yFactor = 1;
                break;

            case 1:
                xFactor = 1;
                yFactor = 0;
                break;

            case 2:
                xFactor = 0;
                yFactor = -1;
                break;

            case 3:
                xFactor = -1;
                yFactor = 0;
                break;

            default:
                Debug.Assert(false);
                break;
            }

            var backTexture     = _getBackTexture();
            var frontTexture    = _getFrontTexture();
            var selectedTexture = _getSelectedTexture();
            var font            = _getFont();

            var middleScaleFactor = .4f;
            var cardHeight        = backTexture.Height * middleScaleFactor;
            var cardWidth         = backTexture.Width * middleScaleFactor;

            var xDistance = cardWidth * 0.8f / 2.0f;
            var yDistance = cardHeight * 0.8f / 2.0f;

            var cardPos = new Vector2(
                centerPosition.X + (xDistance * xFactor),
                centerPosition.Y + (yDistance * yFactor) + (cardHeight * 2.5f) // * 2.5f negates the card's internal origin offset
                );

            // Draw the card in the middle
            _cardGraphics[card] = new DevCard(backTexture, frontTexture, selectedTexture, font)
            {
                Angle       = 0,
                Card        = card,
                IsCovered   = false,
                IsSelected  = false,
                Position    = cardPos,
                ScaleFactor = middleScaleFactor
            };
            _drawingOrder.Remove(card);
            _drawingOrder.Add(card);
            _middleCards.Add(card);
            if (_clickableCards.Contains(card))
            {
                _clickableCards.Remove(card);
            }
        }