Example #1
0
 /// <summary>
 /// Check if Card equals another card.
 /// </summary>
 /// <param name="c"></param>
 /// <returns></returns>
 public Boolean Equals(Card c)
 {
     if (c == null) return false;
     else if ((suit.Equals(c.getSuit())) && (value == c.getValue()))
     {
         return true;
     }
     else return false;
 }
Example #2
0
        /// <summary>
        /// Add card c to tableu
        /// </summary>
        /// <param name="x"></param>
        public void addCardToTableu(Card c)
        {
            Boolean inTableu = false;

            for (int i = 0; i < getTableuSize(); i++)
            {
                if (tableuList.ElementAt(i).Equals(c))
                {
                    inTableu = true;
                    break;
                }
            }

            if (inTableu)
            {
                c.setVector(new Vector2((int)tableuVector.X, (int)tableuVector.Y + ((getTableuSize()-1) * 20)));
            }

            else c.setVector(new Vector2((int)tableuVector.X, (int)tableuVector.Y + (getTableuSize() * 20)));

            c.setTableu(tableuName);

            tableuList.Add(c);
        }
Example #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // get location of the mouse
            x = Mouse.GetState().X;
            y = Mouse.GetState().Y;

            // Allows the game to exit
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            // Allows the game to reset
            if (Keyboard.GetState().IsKeyDown(Keys.R))
            {
                readyToPlay = false;
                win = false;
                this.gameTableus = new List<Tableu>(); ;
                this.gameFoundations = new List<Foundation>(); ;
                this.playerScore = 0;
                this.Initialize();
            }

            // Allows the game to reset
            if (Keyboard.GetState().IsKeyDown(Keys.H))
            {
                help = true;
            }
            else
            {
                help = false;
            }

            Boolean draggedToTableu = false;
            Boolean draggedToFoundation = false;

            //Right clicking will check if selected card can fit on a tableu, and if so, will move to legal tableu
               /* if (!dragging && (Mouse.GetState().RightButton == ButtonState.Pressed))

            * */

            // If not dragging and mouse left button is pressed, check if mouse is within card bounds.
            if (!dragging && (Mouse.GetState().LeftButton == ButtonState.Pressed))
            {
                tempTableu = null;
                temp = null;

                // Find original tableu
                for (int i = 0; i < gameTableus.Count; i++)
                {
                    if(gameTableus.ElementAt(i).contains(new Vector2(x,y)))
                    {
                        tempTableu = gameTableus.ElementAt(i);
                    }
                }

                // If tableu is not empty then get the top card
                if (tempTableu != null) temp = tempTableu.getTopCard();

                // If card exist under mouse pointer pick up the card
                if (temp!=null && tempTableu != null)
                {
                    dragging = true;
                }
            }

            // Stop dragging if button is released.
            if (dragging && Mouse.GetState().LeftButton == ButtonState.Released)
            {
                dragging = false;

                // Moving card to Tableus
                for (int i = 0; i < gameTableus.Count; i++)
                {
                   if (gameTableus.ElementAt(i).contains(new Vector2(x, y)))
                    {
                        // check if move is valid
                        // topCard is not null (tableu is not empty)
                        // dragged card is 1 less than topCard
                        if (gameTableus.ElementAt(i).getTopCard() != null && gameTableus.ElementAt(i).getTopCard().is1LessThan(temp))
                        {
                            // moved to a new Tableu
                            draggedToTableu = true;
                            tempTableu.removeCard(temp);
                            gameTableus.ElementAt(i).addCardToTableu(temp);

                        }
                    }
                }

                // Moving card to Foundation
                for (int i = 0; i < gameFoundations.Count; i++)
                {
                    if (gameFoundations.ElementAt(i).contains(new Vector2(x, y)))
                    {
                        // If the foundation is empty and the card an Ace, allow it to be place on an empty foundation.
                        if (gameFoundations.ElementAt(i).isEmpty() && temp.isAce())
                        {
                            // moved to a new Foundation
                            gameFoundations.ElementAt(i).addCardToFoundation(temp);
                            tempTableu.removeCard(temp);
                            draggedToFoundation = true;
                            playerScore += 10;
                        }
                        // else if the suit matched the foundation and it is one more than previous, allow it to be placed.
                        else if (gameFoundations.ElementAt(i).getTopCard().suitMatches(temp) && gameFoundations.ElementAt(i).getTopCard().is1MoreThan(temp))
                        {
                            // moved to a new Foundation
                            gameFoundations.ElementAt(i).addCardToFoundation(temp);
                            tempTableu.removeCard(temp);
                            draggedToFoundation = true;
                            playerScore += 10;
                        }
                    }
                }

                // Return card to original location.
                if (draggedToTableu == false && draggedToFoundation == false)
                {
                    tempTableu.addCardToTableu(temp);
                    tempTableu.removeCard(temp);
                }

            }

            DragCard();

            // remove all empty tableus
            RemoveEmptyTableus();
            int count = 0;
            //Check for Win
            for (int i = 0; i < gameFoundations.Count; i++)
            {
                if (gameFoundations.ElementAt(i).isFull())
                {
                    count++;
                }
            }
            if (count == 4) win = true;

            // Debug: Where is the mouse, sprite, and vector at.
             //try
             //   {
             //       System.Diagnostics.Debug.Print("Update: Mouse at: " + x + ", " + y + ". Card at: " + temp.getSprite().Bounds + ". Vector at: " + temp.getVector());
             //   }
             //   catch (Exception)
             //   {
             //       System.Diagnostics.Debug.Print("Update: Mouse at: " + x + ", " + y + ". Card is Null");
             //   }

            base.Update(gameTime);
        }
Example #4
0
 /// <summary>
 /// Add card c to foundation
 /// </summary>
 /// <param name="x"></param>
 public void addCardToFoundation(Card c)
 {
     c.setVector(new Vector2((int)foundationVector.X, (int)foundationVector.Y));
     foundationList.Add(c);
 }
Example #5
0
        /// <summary>
        /// Remove card c from foundation
        /// </summary>
        /// <param name="x"></param>
        public void removeCard(Card c)
        {
            //for (int i = 0; i < foundationList.Count; i++)
            //{
            //    if (foundationList.ElementAt(i).Equals(c))
            //    {
            //        foundationList.RemoveAt(i);
            //    }
            //}

            foundationList.RemoveAt(getFoundationSize() - 1);
        }
Example #6
0
 /// <summary>
 /// Remove card c from tableu
 /// </summary>
 /// <param name="x"></param>
 public void removeCard(Card c)
 {
     tableuList.RemoveAt(getTableuSize()-1);
 }
Example #7
0
        /// <summary>
        /// If this tableu has a king in it, then make it the bottom most card.
        /// </summary>
        public void makeKingBottom(int j)
        {
            Card king = new Card();
            List<Card> tempTableu = new List<Card>();
            int pos = 0;
            Boolean isKing = false;

               // Find where king is
            for (int i = j; i < getTableuSize(); i++)
            {
                if (tableuList.ElementAt(i).isKing())
                {
                    king = new Card(tableuList.ElementAt(i).getSuit(), tableuList.ElementAt(i).getValue(), tableuList.ElementAt(i).getSprite());
                    pos = i;
                    isKing = true;
                    break;
                }
            }

            if (isKing)
            {
                //Remove king
                tableuList.RemoveAt(pos);

                // Make temp Tableu
                tempTableu.AddRange(tableuList);

                // Empty tableu list;
                tableuList.RemoveRange(0, tableuList.Count);

                // Add king
                addCardToTableu(king);

                for (int i = 0; i < tempTableu.Count; i++)
                {
                    if (tempTableu.ElementAt(i) != null) addCardToTableu(tempTableu.ElementAt(i));
                }
            }
        }
Example #8
0
 /// <summary>
 /// Check if values match
 /// </summary>
 /// <param name="c"></param>
 /// <returns></returns>
 public Boolean valueMatches(Card c)
 {
     if (getValue() == c.getValue()) return true;
     else return false;
 }
Example #9
0
 /// <summary>
 /// Checks if suit matches
 /// </summary>
 /// <param name="c"></param>
 /// <returns></returns>
 public Boolean suitMatches(Card c)
 {
     if (suit.Equals(c.getSuit()))
     {
         return true;
     }
     else return false;
 }
Example #10
0
 /// <summary>
 /// Check if card is 1 More than given card
 /// </summary>
 /// <param name="c"></param>
 /// <returns></returns>
 public Boolean is1MoreThan(Card c)
 {
     if (c.getValue()-getValue() == 1)
     {
         return true;
     }
     return false;
 }
Example #11
0
 /// <summary>
 /// Check if card is 1 less than given card
 /// </summary>
 /// <param name="c"></param>
 /// <returns></returns>
 public Boolean is1LessThan(Card c)
 {
     if (getValue()-c.getValue() == 1)
     {
         return true;
     }
     return false;
 }
Example #12
0
 /// <summary>
 /// Add card c to list
 /// </summary>
 /// <param name="x"></param>
 public void addCard(Card c)
 {
     cardList.Add(c);
 }