Пример #1
0
        /// <summary>
        /// Initializes a new instance of the animated hand component. This means
        /// setting the hand's position and initializing all animated cards and their
        /// respective positions. Also, registrations are performed to the associated
        /// <paramref name="hand"/> events to update the animated hand as cards are
        /// added or removed.
        /// </summary>
        /// <param name="place">The player's place index (-1 for the dealer).</param>
        /// <param name="hand">The hand represented by this instance.</param>
        /// <param name="cardGame">The associated card game.</param>
        public AnimatedHandGameComponent(int place, Hand hand, CardsGame cardGame)
            : base(cardGame, null)
        {
            Place              = place;
            Hand               = hand;
            hand.ReceivedCard += Hand_ReceivedCard;
            hand.LostCard     += Hand_LostCard;

            // Set the component's position
            if (place == -1)
            {
                CurrentPosition = CardGame.GameTable.DealerPosition;
            }
            else
            {
                CurrentPosition = CardGame.GameTable[place];
            }

            // Create and initialize animated cards according to the cards in the
            // associated hand
            for (int cardIndex = 0; cardIndex < hand.Count; cardIndex++)
            {
                AnimatedCardsGameComponent animatedCardGameComponent =
                    new AnimatedCardsGameComponent(hand[cardIndex], CardGame)
                {
                    CurrentPosition = CurrentPosition + new Vector2(30 * cardIndex, 0)
                };

                heldAnimatedCards.Add(animatedCardGameComponent);
                Game.Components.Add(animatedCardGameComponent);
            }

            Game.Components.ComponentRemoved += Components_ComponentRemoved;
        }
        /// <summary>
        /// Initializes a new instance of the animated hand component. This means
        /// setting the hand's position and initializing all animated cards and their
        /// respective positions. Also, registrations are performed to the associated
        /// <paramref name="hand"/> events to update the animated hand as cards are
        /// added or removed.
        /// </summary>
        /// <param name="place">The player's place index (-1 for the dealer).</param>
        /// <param name="hand">The hand represented by this instance.</param>
        /// <param name="cardGame">The associated card game.</param>
        public AnimatedHandGameComponent(int place, Hand hand, CardsGame cardGame)
            : base(cardGame, null)
        {
            Place = place;
            Hand = hand;
            hand.ReceivedCard += Hand_ReceivedCard;
            hand.LostCard += Hand_LostCard;

            // Set the component's position
            if (place == -1)
            {
                CurrentPosition = CardGame.GameTable.DealerPosition;
            }
            else
            {
                CurrentPosition = CardGame.GameTable[place];
            }

            // Create and initialize animated cards according to the cards in the
            // associated hand
            for (int cardIndex = 0; cardIndex < hand.Count; cardIndex++)
            {
                AnimatedCardsGameComponent animatedCardGameComponent =
                    new AnimatedCardsGameComponent(hand[cardIndex], CardGame)
                    {
                        CurrentPosition = CurrentPosition + new Vector2(30 * cardIndex, 0)
                    };

                heldAnimatedCards.Add(animatedCardGameComponent);
                Game.Components.Add(animatedCardGameComponent);
            }

            Game.Components.ComponentRemoved += Components_ComponentRemoved;
        }
Пример #3
0
        /// <summary>
        /// Handles the hand's ReceivedCard event be adding a corresponding
        /// animated card.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The
        /// <see cref="CardsFramework.CardEventArgs"/>
        /// instance containing the event data.</param>
        void Hand_ReceivedCard(object sender, CardEventArgs e)
        {
            // Add the card to the screen
            AnimatedCardsGameComponent animatedCardGameComponent =
                new AnimatedCardsGameComponent(e.Card, CardGame)
            {
                Visible = false
            };

            heldAnimatedCards.Add(animatedCardGameComponent);
            Game.Components.Add(animatedCardGameComponent);
        }
        /// <summary>
        /// Handles the hand's ReceivedCard event be adding a corresponding 
        /// animated card.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The 
        /// <see cref="CardsFramework.CardEventArgs"/> 
        /// instance containing the event data.</param>
        void Hand_ReceivedCard(object sender, CardEventArgs e)
        {
            // Add the card to the screen
            AnimatedCardsGameComponent animatedCardGameComponent =
                new AnimatedCardsGameComponent(e.Card, CardGame) { Visible = false };

            heldAnimatedCards.Add(animatedCardGameComponent);
            Game.Components.Add(animatedCardGameComponent);
        }