Ejemplo n.º 1
0
        /// <summary>
        /// Solitaire game logic -check
        /// </summary>
        /// <param name="c"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        private bool isAcceptedMove(Card c, Deck to)
        {
            // Accept card moves only to type 1 and 2 decks
            if (to.Type() != Deck.DeckType.EUserDeck && to.Type() != Deck.DeckType.ETargetDeck)
            {
                return(false);
            }

            if (to.CardCount() > 0)
            {
                // Moving top of card
                Card toOnCard = to.GetLast();

                // Moving cards between card decks
                if (toOnCard.OwnerDeck.Type() == Deck.DeckType.EUserDeck)
                {
                    // Card decks must differ
                    if (c.OwnerDeck == toOnCard.OwnerDeck)
                    {
                        return(false);
                    }
                    // Card can be top of one step greater card and different color
                    // Card can not be same color
                    if (c.CardLand() == toOnCard.CardLand() || toOnCard.CardId() != c.CardId() + 1 || c.IsBlack() == toOnCard.IsBlack())
                    {
                        return(false);
                    }
                }
                else if (toOnCard.OwnerDeck.Type() == Deck.DeckType.ETargetDeck)
                {
                    // Cards must be in ascending order and same suite in 2 target deck
                    if (toOnCard.CardId() + 1 != c.CardId() || toOnCard.CardLand() != c.CardLand())
                    {
                        return(false);
                    }
                }
            }
            else
            {
                // Moving top of empty deck

                // If there is no cards in the deck, then the first one must be King card in source decks 1
                if (to.CardCount() == 0 && c.CardId() != 13 && to.Type() == Deck.DeckType.EUserDeck)
                {
                    return(false);
                }

                // Ace card must be the first card in foundation
                if (to.Type() == Deck.DeckType.ETargetDeck && to.CardCount() == 0 && c.CardId() != 1)
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo 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);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Solitaire game logic -check
        /// </summary>
        /// <param name="c"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        private bool isAcceptedMove(Card c, Deck to)
        {
            // Accept card moves only to type 1 and 2 decks
            if (to.Type() != Deck.DeckType.EUserDeck && to.Type() != Deck.DeckType.ETargetDeck)
                return false;

            if (to.CardCount() > 0)
            {
                // Moving top of card
                Card toOnCard = to.GetLast();

                // Moving cards between card decks
                if (toOnCard.OwnerDeck.Type() == Deck.DeckType.EUserDeck)
                {
                    // Card decks must differ
                    if (c.OwnerDeck == toOnCard.OwnerDeck)
                        return false;
                    // Card can be top of one step greater card and different color
                    // Card can not be same color
                    if (c.CardLand() == toOnCard.CardLand() || toOnCard.CardId() != c.CardId() + 1 || c.IsBlack() == toOnCard.IsBlack())
                        return false;
                }
                else if (toOnCard.OwnerDeck.Type() == Deck.DeckType.ETargetDeck)
                {
                    // Cards must be in ascending order and same suite in 2 target deck
                    if (toOnCard.CardId() + 1 != c.CardId() || toOnCard.CardLand() != c.CardLand())
                        return false;
                }
            }
            else
            {
                // Moving top of empty deck

                // If there is no cards in the deck, then the first one must be King card in source decks 1
                if (to.CardCount() == 0 && c.CardId() != 13 && to.Type() == Deck.DeckType.EUserDeck)
                    return false;

                // Ace card must be the first card in foundation
                if (to.Type() == Deck.DeckType.ETargetDeck && to.CardCount() == 0 && c.CardId() != 1)
                    return false;

            }
            return true;
        }
Ejemplo n.º 4
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();
                    }
                }
            }
        }