Exemple #1
0
        /// <summary>
        /// Move card back to the original position
        /// </summary>
        public void cancelMove()
        {
            // Move card back to original position
            m_rect = m_originRect;

            // Move also parent card move
            if (p_parentCard != null)
            {
                p_parentCard.cancelMove();
            }
        }
Exemple #2
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();
                    }
                }
            }
        }