示例#1
0
        public void Draw(SpriteBatch spriteBatch, GraphicsDevice graphics, SpriteFont font)
        {
            // Calculate hand location on screen
            var screenWidth = graphics.PresentationParameters.BackBufferWidth;
            var y = _topHand ? 0 : graphics.PresentationParameters.BackBufferHeight - _cardHeight;
            var initHorizontalOffset = (screenWidth - _hand.Cards.Count * _cardWidth) / 2;

            // Create CardObject for each card in hand
            var cards = new List<CardObject>();
            foreach (var c in _hand.Cards.Select((x,i) => new { Card = x, Index = i }) )
            {
                var location = new Vector2(initHorizontalOffset + _cardWidth * c.Index, y);
                var texture = _cardsDB.LookupTexture(c.Card);

                var m = new Point(_mouseState.X, _mouseState.Y);
                var cardBounds = new Rectangle ((int)location.X, (int)location.Y, _cardWidth, _cardHeight);
                var selected = cardBounds.Contains(m);

                if (DateTime.Now.Millisecond == 0)
                {
                    Debug.WriteLine(cardBounds);
                    Debug.WriteLine(m);
                }

                var card = new CardObject(texture, location, _cardHeight, _cardWidth, 1, c.Card.FaceDown, selected);
                cards.Add(card);
            }

            // Loop through CardObjects and let them draw themselves in the right position
            foreach (var c in cards)
            {
                c.Draw(spriteBatch, graphics, font);
            }
        }
        public void Draw(SpriteBatch spriteBatch, GraphicsDevice graphics, SpriteFont font)
        {
            // Calculate zone location on screen
            var screenHeight = graphics.PresentationParameters.BackBufferHeight;
            var screenWidth = graphics.PresentationParameters.BackBufferWidth;
            var padding = 5;
            var factoredPadding = padding * _factor;

            var height = (_cardHeight + 2 * factoredPadding);
            var width = ((_cardWidth + factoredPadding) * _battleZone.Capacity + factoredPadding);

            var offset = ((height + padding * 10) * _factor) / 2;
            var top = screenHeight / 2 - (_topZone ? offset : - offset - factoredPadding + height);
            var left = (screenWidth - width) / 2;

            var cardsTop = top + factoredPadding;
            var cardsLeft = left + factoredPadding;

            // Create CardObject for each card in hand
            var cards = new List<CardObject>();

            var m = new Point(_mouseState.X, _mouseState.Y);
            var cardCount = 0;

            // Draw the Zone

            DrawZone(spriteBatch, graphics, Color.Purple, left, top, width, height);

            // Draw the Cards
            foreach (var c in _battleZone.Cards.Select((x,i) => new { Card = x, Index = i }) )
            {
                var location = new Vector2(cardsLeft + (_cardWidth + padding) * _factor, cardsTop);
                var texture = _cardsDB.LookupTexture(c.Card);

                var cardBounds = new Rectangle ((int)location.X, (int)location.Y, _cardWidth, _cardHeight);
                var selected = cardBounds.Contains(m);

                var card = new CardObject(texture, location, _cardHeight, _cardWidth, 1, c.Card.FaceDown, selected);
                cards.Add(card);
                cardCount++;
            }

            // Creates empty Cards to fill in the BattleZone
            for (var i = 0; i < _battleZone.AvailableSlots; i++)
            {
                var location = new Vector2(cardsLeft + cardCount * (_cardWidth + factoredPadding), cardsTop);
                var cardBounds = new Rectangle((int)location.X, (int)location.Y, _cardWidth, _cardHeight);
                var selected = cardBounds.Contains(m);

                cards.Add(new CardObject(null, location, _cardHeight, _cardWidth, 1, false, selected, true));
                cardCount++;
            }

            // Loop through CardObjects and let them draw themselves in the right position
            foreach (var c in cards)
            {
                c.Draw(spriteBatch, graphics, font);
            }
        }