Exemplo n.º 1
0
        /// <summary>
        /// Adds new card to this deck
        /// </summary>
        /// <param name="newCard"></param>
        public override void AddCard(Card newCard)
        {
            // All cards in the deck are in same position
            Rectangle r = newCard.CardRectangle;
            Point p = m_pos;
            r.Location = p;
            newCard.CardRectangle = r;

            newCard.m_z = Game1.nextZ();

            if (m_cards.Count() > 0)
            {
                if (newCard.ChildCard != null)
                {
                    // Clear previous child parent
                    newCard.ChildCard.ParentCard = null;
                }
            }
            else
            {
                // Deck is empty
                if (newCard.ChildCard != null)
                {
                    // Clear previous child parent
                    newCard.ChildCard.ParentCard = null;
                }
                newCard.ChildCard = null;
            }

            // Mark owner deck into card
            newCard.OwnerDeck = this;

            // Add card into this deck
            m_cards.Add(newCard);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create SolitaireData from Card
 /// </summary>
 /// <param name="card"></param>
 /// <param name="internalDeckId"></param>
 public void AddCardData(Card card, int internalDeckId)
 {
     m_land = (int)card.CardLand();
     m_id = card.CardId();
     m_isBlack = card.IsBlack();
     m_isTurned = card.IsTurned();
     m_internalDeckId = internalDeckId;
     m_z = card.m_z;
 }
Exemplo n.º 3
0
        public Card(int land, int id, int z)
        {
            m_z = z;
            p_parentCard = null;
            p_childCard = null;
            p_ownerDeck = null;

            // Black or red card?
            if (land == (int)Card.CardLandEnum.EClubs || land == (int)Card.CardLandEnum.ESpade)
                m_isBlack = true;
        }
Exemplo n.º 4
0
        Card p_parentCard; // Upper / parent card

        #endregion Fields

        #region Constructors

        public Card(CardLandEnum land, int id, int z, ContentManager theContentManager)
        {
            m_z = z;
            p_parentCard = null;
            p_childCard = null;
            p_ownerDeck = null;

            // Black or red card?
            if (land == Card.CardLandEnum.EClubs || land == Card.CardLandEnum.ESpade)
                m_isBlack = true;

            this.LoadCard(land, id, theContentManager);
        }
Exemplo n.º 5
0
 public override void AddParentCard(Card parent)
 {
     // No impl, have to be empty
 }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
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();
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            System.Diagnostics.Debug.WriteLine("Initialize");

            if (PhoneApplicationService.Current.StartupMode == StartupMode.Activate)
            {
                System.Diagnostics.Debug.WriteLine("StartupMode.Activate");
                m_fromTombstoned = true;
            }
            else if (PhoneApplicationService.Current.StartupMode == StartupMode.Launch)
            {
                System.Diagnostics.Debug.WriteLine("StartupMode.Launch");
            }

            p_activeCard = null;
            m_sourceDeck.p_wasteDeck = m_wasteDeck;

            // Screen rectangle
            m_rect = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            // Create all decks
            int cap = CARD_CAP;
            m_deck.Position = new Point(cap, 180);
            m_deckList.Add(m_deck);
            m_deck2.Position = new Point(cap * 2 + Card.CARD_WIDTH, 180);
            m_deckList.Add(m_deck2);
            m_deck3.Position = new Point(cap * 3 + Card.CARD_WIDTH * 2, 180);
            m_deckList.Add(m_deck3);
            m_deck4.Position = new Point(cap * 4 + Card.CARD_WIDTH * 3, 180);
            m_deckList.Add(m_deck4);
            m_deck5.Position = new Point(cap * 5 + Card.CARD_WIDTH * 4, 180);
            m_deckList.Add(m_deck5);
            m_deck6.Position = new Point(cap * 6 + Card.CARD_WIDTH * 5, 180);
            m_deckList.Add(m_deck6);
            m_deck7.Position = new Point(cap * 7 + Card.CARD_WIDTH * 6, 180);
            m_deckList.Add(m_deck7);

            m_targetdeck.Position = new Point(m_deck4.Position.X, cap);
            m_deckList.Add(m_targetdeck);
            m_targetdeck2.Position = new Point(m_deck5.Position.X, cap);
            m_deckList.Add(m_targetdeck2);
            m_targetdeck3.Position = new Point(m_deck6.Position.X, cap);
            m_deckList.Add(m_targetdeck3);
            m_targetdeck4.Position = new Point(m_deck7.Position.X, cap);
            m_deckList.Add(m_targetdeck4);

            m_sourceDeck.Position = new Point(m_deck.Position.X, cap);
            m_deckList.Add(m_sourceDeck);
            m_wasteDeck.Position = new Point(m_deck.Position.X + Card.CARD_WIDTH + cap, cap);
            m_deckList.Add(m_wasteDeck);

            base.Initialize();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Adds new card to this deck
        /// </summary>
        /// <param name="newCard"></param>
        public virtual void AddCard(Card newCard)
        {
            // Cards are positioned with 20 pixcels cap
            Rectangle r = newCard.CardRectangle;
            Point p = m_pos;
            p.Y = p.Y + (Card.CARD_CAP * m_cards.Count());
            r.Location = p;
            newCard.CardRectangle = r;

            newCard.m_z = Game1.nextZ();

            if (m_cards.Count() > 0)
            {
                // Deck has cards
                Card lastCard = m_cards.Last();
                lastCard.ParentCard = newCard;

                if (newCard.ChildCard != null)
                {
                    // Clear previous child parent
                    newCard.ChildCard.ParentCard = null;
                    // Set new child card
                    newCard.ChildCard = lastCard;
                }
                else
                {
                    // Add new child card
                    newCard.ChildCard = lastCard;
                }
            }
            else
            {
                // Deck is empty
                if (newCard.ChildCard != null)
                {
                    // Clear previous child parent
                    newCard.ChildCard.ParentCard = null;
                }
                newCard.ChildCard = null;
            }

            // Mark owner deck into card
            newCard.OwnerDeck = this;

            // Add card into this deck
            m_cards.Add(newCard);

            // Add also all parent cards into this deck
            if (newCard.ParentCard != null)
            {
                AddParentCard(newCard.ParentCard);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Removes card from the deck
        /// </summary>
        /// <param name="c"></param>
        public virtual void RemoveCard(Card c)
        {
            // Remove card from the deck
            m_cards.Remove(c);

            // Remove also all parent cards from the this deck
            if (c.ParentCard != null)
            {
                RemoveCard(c.ParentCard);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Used when user moves many cards on the same time between decks
        /// </summary>
        /// <param name="parent"></param>
        public virtual void AddParentCard(Card parent)
        {
            // Add parent card to this deck

            // Cards are positioned with 20 pixcels cap
            Rectangle r = parent.CardRectangle;
            Point p = m_pos;
            p.Y = p.Y + (Card.CARD_CAP * m_cards.Count());
            r.Location = p;
            parent.CardRectangle = r;
            parent.m_z = Game1.nextZ();

            // Mark owner deck into card
            parent.OwnerDeck = this;

            // Add card into this deck
            m_cards.Add(parent);

            // Add also all parent cards into this deck
            if (parent.ParentCard != null)
            {
                AddParentCard(parent.ParentCard);
            }
        }