Esempio n. 1
0
        /// <summary>
        /// Handles touch
        /// </summary>
        /// <param name="tl"></param>
        /// <returns></returns>
        public virtual Card HandleTouch(TouchLocation tl)
        {
            Card ret = null;

            foreach (Card c in m_cards)
            {
                if (c.isInTouch(tl))
                {
                    // Take most upper cards from the deck
                    if (ret != null && ret.m_z < c.m_z)
                    {
                        ret = c;
                    }
                    else if (ret == null)
                    {
                        ret = c;
                    }
                }
            }
            // If card found, handle touch
            if (ret != null)
            {
                ret.handleTouch(tl);
            }
            return(ret);
        }
Esempio n. 2
0
        /// <summary>
        /// Process Pressed and Moved touch
        /// </summary>
        /// <param name="tl"></param>
        public void handleTouch(TouchLocation tl)
        {
            if (tl.State == TouchLocationState.Pressed)
            {
                m_originRect = m_rect;
                m_xCap       = (int)tl.Position.X - m_rect.X;
                m_yCap       = (int)tl.Position.Y - m_rect.Y;
            }
            else if (tl.State == TouchLocationState.Moved)
            {
                // Allow move card only from deck 1 and 4
                if ((p_ownerDeck.Type() == Deck.DeckType.EUserDeck || p_ownerDeck.Type() == Deck.DeckType.EWasteDeck))
                {
                    m_rect.X = (int)tl.Position.X - m_xCap;
                    m_rect.Y = (int)tl.Position.Y - m_yCap;
                }
            }

            // Handle press and move of also all turned parent cards
            if (p_parentCard != null && p_parentCard.m_isTurned)
            {
                p_parentCard.handleTouch(tl);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Handle user touch events: Pressed, Moved, Released
        /// </summary>
        private void handleTouch()
        {
            // Handle all touch here
            TouchCollection touchCollection = TouchPanel.GetState();

            if (touchCollection.Count() > 0)
            {
                TouchLocation tl = touchCollection.First();

                if (tl.State == TouchLocationState.Pressed)
                {
                    // Handle deck touch and find active card
                    Card ret = null;
                    for (int di = 0; di < m_deckList.Count; di++)
                    {
                        ret = m_deckList[di].HandleTouch(tl);
                        if (ret != null)
                        {
                            break;
                        }
                    }
                    // Accept to select cards?
                    if (ret != null && ret.OwnerDeck.Type() != Deck.DeckType.ESourceDeck)
                    {
                        // Turn card and activate
                        if (!ret.IsTurned())
                        {
                            if (ret.ParentCard == null)
                            {
                                ret.setTurned(true);
                                p_activeCard = ret;
                            }
                        }
                        // Car is turned
                        // Set active card under move
                        else
                        {
                            p_activeCard = ret;
                        }
                    }
                }
                else if (tl.State == TouchLocationState.Moved)
                {
                    // If active card, move it
                    if (p_activeCard != null)
                    {
                        p_activeCard.handleTouch(tl);
                    }
                }
                else if (tl.State == TouchLocationState.Released)
                {
                    // Where active card was released?
                    if (p_activeCard != null)
                    {
                        // Accept moving cards only from target and source decks
                        Deck fromDeck = p_activeCard.OwnerDeck;
                        if (fromDeck != null && (fromDeck.Type() == Deck.DeckType.EUserDeck ||
                                                 fromDeck.Type() == Deck.DeckType.EWasteDeck))
                        {
                            // Find deck where card was released, accept target and source decks only
                            Deck toDeck = GetDeckUnderTouch(tl);
                            if (toDeck != null && (toDeck.Type() == Deck.DeckType.EUserDeck ||
                                                   toDeck.Type() == Deck.DeckType.ETargetDeck))
                            {
                                if (toDeck == fromDeck)
                                {
                                    // cancel move
                                    p_activeCard.cancelMove();
                                }
                                else
                                {
                                    // Check is this card move acceptable
                                    if (isAcceptedMove(p_activeCard, toDeck))
                                    {
                                        // Accept move
                                        fromDeck.RemoveCard(p_activeCard);
                                        toDeck.AddCard(p_activeCard);
                                    }
                                    else
                                    {
                                        // Cancel move
                                        p_activeCard.cancelMove();
                                    }
                                }
                            }
                            else
                            {
                                // Trying to move card between not acceptable decks
                                p_activeCard.cancelMove();
                            }
                        }
                        else
                        {
                            // Trying to move card between not acceptable decks
                            p_activeCard.cancelMove();
                        }
                        // Reset active card, no moving ongoing
                        p_activeCard = null;
                    }


                    int count = 0;
                    for (int i = 0; i < m_deckList.Count(); i++)
                    {
                        count += m_deckList[i].CardCount();
                    }
                }
            }
        }