示例#1
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();
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Create Deck list from SolitaireDataList
        /// </summary>
        /// <param name="toDeckList"></param>
        /// <param name="allCards"></param>
        public void ReadDeckDataToList(ref List <Deck> toDeckList, ref List <Card> allCards)
        {
            Deck userDeck1 = null;
            Deck userDeck2 = null;
            Deck userDeck3 = null;
            Deck userDeck4 = null;
            Deck userDeck5 = null;
            Deck userDeck6 = null;
            Deck userDeck7 = null;

            TargetDeck targetDeck1 = null;
            TargetDeck targetDeck2 = null;
            TargetDeck targetDeck3 = null;
            TargetDeck targetDeck4 = null;

            SourceDeck sourceDeck = null;
            WasteDeck  wasteDeck  = null;

            // Find right decks, have to use internal deck id for matching
            for (int i = 0; i < toDeckList.Count(); i++)
            {
                Deck deck = toDeckList[i];
                if (deck.InternalDeckId() == 10)
                {
                    userDeck1 = deck;
                }
                else if (deck.InternalDeckId() == 20)
                {
                    userDeck2 = deck;
                }
                else if (deck.InternalDeckId() == 30)
                {
                    userDeck3 = deck;
                }
                else if (deck.InternalDeckId() == 40)
                {
                    userDeck4 = deck;
                }
                else if (deck.InternalDeckId() == 50)
                {
                    userDeck5 = deck;
                }
                else if (deck.InternalDeckId() == 60)
                {
                    userDeck6 = deck;
                }
                else if (deck.InternalDeckId() == 70)
                {
                    userDeck7 = deck;
                }
                else if (deck.InternalDeckId() == 100)
                {
                    targetDeck1 = (TargetDeck)deck;
                }
                else if (deck.InternalDeckId() == 200)
                {
                    targetDeck2 = (TargetDeck)deck;
                }
                else if (deck.InternalDeckId() == 300)
                {
                    targetDeck3 = (TargetDeck)deck;
                }
                else if (deck.InternalDeckId() == 400)
                {
                    targetDeck4 = (TargetDeck)deck;
                }
                else if (deck.InternalDeckId() == 1000)
                {
                    sourceDeck = (SourceDeck)deck;
                }
                else if (deck.InternalDeckId() == 2000)
                {
                    wasteDeck = (WasteDeck)deck;
                }
            }

            // Add cards into right decks
            for (int i = 0; i < m_list.Count(); i++)
            {
                // Tombstoned card data list
                SolitaireData data = m_list[i];

                // Find card class
                Card c = findCard(ref allCards, data.m_land, data.m_id);
                if (c == null)
                {
                    break;
                }
                c.setTurned(data.m_isTurned);

                // Set card into right deck
                switch (data.m_internalDeckId)
                {
                case 10:
                {
                    userDeck1.AddCard(c);
                    break;
                }

                case 20:
                {
                    userDeck2.AddCard(c);
                    break;
                }

                case 30:
                {
                    userDeck3.AddCard(c);
                    break;
                }

                case 40:
                {
                    userDeck4.AddCard(c);
                    break;
                }

                case 50:
                {
                    userDeck5.AddCard(c);
                    break;
                }

                case 60:
                {
                    userDeck6.AddCard(c);
                    break;
                }

                case 70:
                {
                    userDeck7.AddCard(c);
                    break;
                }

                case 100:
                {
                    targetDeck1.AddCard(c);
                    break;
                }

                case 200:
                {
                    targetDeck2.AddCard(c);
                    break;
                }

                case 300:
                {
                    targetDeck3.AddCard(c);
                    break;
                }

                case 400:
                {
                    targetDeck4.AddCard(c);
                    break;
                }

                case 1000:
                {
                    sourceDeck.AddCard(c);
                    break;
                }

                case 2000:
                {
                    wasteDeck.AddCard(c);
                    break;
                }
                }
            }
        }
示例#3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            System.Diagnostics.Debug.WriteLine("LoadContent");

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            m_background = this.Content.Load <Texture2D>("background");

            // Create all cards
            for (int i = 1; i < 14; i++)
            {
                m_allCards.Add(new Card(Card.CardLandEnum.EClubs, i, nextZ(), this.Content));
            }

            for (int i = 1; i < 14; i++)
            {
                m_allCards.Add(new Card(Card.CardLandEnum.EDiamond, i, nextZ(), this.Content));
            }

            for (int i = 1; i < 14; i++)
            {
                m_allCards.Add(new Card(Card.CardLandEnum.ESpade, i, nextZ(), this.Content));
            }

            for (int i = 1; i < 14; i++)
            {
                m_allCards.Add(new Card(Card.CardLandEnum.EHeart, i, nextZ(), this.Content));
            }


            m_deck.LoadBackground(this.Content);
            m_deck2.LoadBackground(this.Content);
            m_deck3.LoadBackground(this.Content);
            m_deck4.LoadBackground(this.Content);
            m_deck5.LoadBackground(this.Content);
            m_deck6.LoadBackground(this.Content);
            m_deck7.LoadBackground(this.Content);
            m_targetdeck.LoadBackground(this.Content);
            m_targetdeck2.LoadBackground(this.Content);
            m_targetdeck3.LoadBackground(this.Content);
            m_targetdeck4.LoadBackground(this.Content);
            m_sourceDeck.LoadBackground(this.Content);
            m_wasteDeck.LoadBackground(this.Content);

            if (!m_fromTombstoned)
            {
                // Create random decks
                Card tmpC = null;
                // Deck 1
                tmpC = GetRandomCard();
                tmpC.setTurned(true);
                m_deck.AddCard(tmpC);

                // Deck 2
                m_deck2.AddCard(GetRandomCard());
                tmpC = GetRandomCard();
                tmpC.setTurned(true);
                m_deck2.AddCard(tmpC);

                // Deck 3
                m_deck3.AddCard(GetRandomCard());
                m_deck3.AddCard(GetRandomCard());
                tmpC = GetRandomCard();
                tmpC.setTurned(true);
                m_deck3.AddCard(tmpC);

                // Deck 4
                m_deck4.AddCard(GetRandomCard());
                m_deck4.AddCard(GetRandomCard());
                m_deck4.AddCard(GetRandomCard());
                tmpC = GetRandomCard();
                tmpC.setTurned(true);
                m_deck4.AddCard(tmpC);

                // Deck 5
                m_deck5.AddCard(GetRandomCard());
                m_deck5.AddCard(GetRandomCard());
                m_deck5.AddCard(GetRandomCard());
                m_deck5.AddCard(GetRandomCard());
                tmpC = GetRandomCard();
                tmpC.setTurned(true);
                m_deck5.AddCard(tmpC);

                // Deck 6
                m_deck6.AddCard(GetRandomCard());
                m_deck6.AddCard(GetRandomCard());
                m_deck6.AddCard(GetRandomCard());
                m_deck6.AddCard(GetRandomCard());
                m_deck6.AddCard(GetRandomCard());
                tmpC = GetRandomCard();
                tmpC.setTurned(true);
                m_deck6.AddCard(tmpC);

                // Deck 7
                m_deck7.AddCard(GetRandomCard());
                m_deck7.AddCard(GetRandomCard());
                m_deck7.AddCard(GetRandomCard());
                m_deck7.AddCard(GetRandomCard());
                m_deck7.AddCard(GetRandomCard());
                m_deck7.AddCard(GetRandomCard());
                tmpC = GetRandomCard();
                tmpC.setTurned(true);
                m_deck7.AddCard(tmpC);

                // Source decks
                for (int i = 0; i < m_allCards.Count(); i++)
                {
                    m_sourceDeck.AddCard(GetRandomCard());
                    i--;
                }
            }
        }