/// <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;
        } 
Esempio n. 2
0
        /// <summary>
        /// Deals the first card from the collection to a specified hand.
        /// </summary>
        /// <param name="destinationHand">The destination hand.</param>
        /// <returns>The card that was moved to the hand.</returns>
        public TraditionalCard DealCardToHand(Hand destinationHand)
        {
            TraditionalCard firstCard = cards[0];

            firstCard.MoveToHand(destinationHand);

            return firstCard;
        }
Esempio n. 3
0
        /// <summary>
        /// Deals several cards to a specified hand.
        /// </summary>
        /// <param name="destinationHand">The destination hand.</param>
        /// <param name="count">The amount of cards to deal.</param>
        /// <returns>A list of the cards that were moved to the hand.</returns>
        public List<TraditionalCard> DealCardsToHand(Hand destinationHand, int count)
        {
            List<TraditionalCard> dealtCards = new List<TraditionalCard>();

            for (int cardIndex = 0; cardIndex < count; cardIndex++)
            {
                dealtCards.Add(DealCardToHand(destinationHand));
            }

            return dealtCards;
        }
 /// <summary>
 /// Moves the card from its current <see cref="CardPacket"/> to the specified <paramref name="hand"/>. 
 /// This method of operation prevents any one card instance from being held by more than one
 /// <see cref="CardPacket"/> at the same time.
 /// </summary>
 /// <param name="hand">The receiving hand.</param>
 public void MoveToHand(Hand hand)
 {
     HoldingCardCollection.Remove(this);
     HoldingCardCollection = hand;
     hand.Add(this);
 }
Esempio n. 5
0
 public Player(string name, CardsGame game)
 {
     Name = name;
     Game = game;
     Hand = new Hand();
 }