Example #1
0
        /// <summary>
        /// Draws (or paints) the cards in the current player's hand.
        /// </summary>
        private void DrawCards()
        {
            // If the player isn't active, the cards will not be face up.
            bool isFaceup = (Owner.State != PlayerState.Inactive);

            // Display the computer player's hand when the game ends.
            if (Owner is ComputerPlayer)
                isFaceup = (Owner.State == PlayerState.Loser || Owner.State == PlayerState.Winner);

            var cards = Owner.GetCards();

            // If the player doesn't have any cards, there's nothing to do.
            if (cards == null || cards.Count == 0)
                return;

            for (var i = 0; i < cards.Count; i++)
            {
                var cardControl = new CardControl(cards[i]);

                if (PlayerOrientation == Orientation.Horizontal)
                    cardControl.Margin = new Thickness(i * 35, 35, 0, 0);
                else
                    cardControl.Margin = new Thickness(5, 35 + i * 30, 0, 0);

                // Connect a double-click event handler to each card, and orient the cards face-up
                // or face-down depending on the setting determined above.
                cardControl.MouseDoubleClick += cardControl_MouseDoubleClick;
                cardControl.IsFaceUp = isFaceup;
                CardSurface.Children.Add(cardControl);
            }
        }
Example #2
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.UserControl = ((KarliCards_Gui.CardControl)(target));
                return;

            case 2:
                this.SuitLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 3:
                this.RankLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 4:
                this.RankLabelInverted = ((System.Windows.Controls.Label)(target));
                return;

            case 5:
                this.TopRightImage = ((System.Windows.Controls.Image)(target));
                return;

            case 6:
                this.BottomLeftImage = ((System.Windows.Controls.Image)(target));
                return;
            }
            this._contentLoaded = true;
        }
Example #3
0
        private void DrawCards()
        {
            bool isFaceup = (Owner.State != PlayerState.Inactive);

            if (Owner is ComputerPlayer)
            {
                isFaceup = (Owner.State == PlayerState.Loser || Owner.State == PlayerState.Winner);
            }
            var cards = Owner.GetCards();

            if (cards == null || cards.Count == 0)
            {
                return;
            }
            for (var i = 0; i < cards.Count; i++)
            {
                var cardControl = new CardControl(cards[i]);
                if (PlayerOrientation == Orientation.Horizontal)
                {
                    cardControl.Margin = new Thickness(i * 35, 35, 0, 0);
                }
                else
                {
                    cardControl.Margin = new Thickness(5, 35 + i * 30, 0, 0);
                }
                cardControl.MouseDoubleClick += cardControl_MouseDoubleClick;
                cardControl.IsFaceUp          = isFaceup;
                CardSurface.Children.Add(cardControl);
            }
        }
        private void DrawDecks()
        {
            controlCanvas.Children.Clear();
            if (CurrentPlayer == null || Deck == null || !GameStarted)
            {
                return;
            }
            List <CardControl> stackedCards = new List <CardControl>();

            for (int i = 0; i < Deck.CardsInDeck; i++)
            {
                stackedCards.Add(new CardControl(Deck.GetCard(i))
                {
                    Margin = new Thickness(150 + (i * 1.25), 25 - (i * 1.25), 0, 0), IsFaceUp = false
                });
            }
            if (stackedCards.Count > 0)
            {
                stackedCards.Last().MouseDoubleClick += Deck_MouseDoubleClick;
            }
            if (AvailableCard != null)
            {
                var availableCard = new CardControl(AvailableCard)
                {
                    Margin = new Thickness(0, 25, 0, 0)
                };
                availableCard.MouseDoubleClick += AvailableCard_MouseDoubleClick;
                controlCanvas.Children.Add(availableCard);
            }
            stackedCards.ForEach(x => controlCanvas.Children.Add(x));
        }
Example #5
0
        /// <summary>
        /// Repaints the game decks.
        /// </summary>
        private void DrawDecks()
        {
            controlCanvas.Children.Clear();

            // Don't do anything if nothing has happened yet.
            if (CurrentPlayer == null || Deck == null || !GameStarted)
            {
                return;
            }

            // Build a stack of card controls for all the cards in the deck.
            List <CardControl> stackedCards = new List <CardControl>();

            for (int i = 0; i < Deck.CardsInDeck; i++)
            {
                stackedCards.Add(
                    new CardControl(Deck.GetCard(i))
                {
                    Margin   = new Thickness(150 + (i * 1.25), 25 - (i * 1.25), 0, 0),
                    IsFaceUp = false
                });
            }

            // If the deck isn't empty, add a double-click event to the top card to make it clickable.
            if (stackedCards.Count > 0)
            {
                stackedCards.Last().MouseDoubleClick += Deck_MouseDoubleClick;
            }

            if (AvailableCard != null)
            {
                var availableCard = new CardControl(AvailableCard)
                {
                    Margin = new Thickness(0, 25, 0, 0)
                };

                // Add a double-click event to the available card.
                availableCard.MouseDoubleClick += AvailableCard_MouseDoubleClick;
                controlCanvas.Children.Add(availableCard);
            }

            stackedCards.ForEach(x => controlCanvas.Children.Add(x));
        }