예제 #1
0
        private void CardPanelMouseDown(object sender, MouseEventArgs e)
        {
            CardPanel clickedCardPanel = (CardPanel)sender;
            Spot      cardSpot         = clickedCardPanel.GetCard().GetSpot();

            _followerCardPanels.Clear();

            //markers cannot move
            if (!clickedCardPanel.GetCard().IsMarker)
            {
                if (cardSpot.GetPile() == Card.Pile.Stock)
                {
                    clickedCardPanel.GetCard().SetSpot(new Spot(Card.Pile.Waste, FindTopCardInPile(new Spot(Card.Pile.Waste)).GetSpot().GetHeight() + 1));
                    clickedCardPanel.GetCard().SetFaceUp();
                }

                //if (clickedCardPanel.GetCard() == FindTopCardInPile(cardSpot))
                if (!clickedCardPanel.GetCard().GetFaceDown())
                {
                    _heldCardPanel = clickedCardPanel;
                    _mouseOffset   = e.Location;

                    //finds all follower cards, revealed cards on top of the held card
                    for (int i = cardSpot.GetHeight() + 1; i <= FindTopCardInPile(
                             cardSpot).GetSpot().GetHeight(); i++)
                    {
                        Card?c = FindCardInSpot(new Spot(cardSpot.GetPile(),
                                                         i, cardSpot.GetColumn()));
                        if (c != null)
                        {
                            CardPanel?cPanel = FindCardPanelByCard(c);
                            if (cPanel != null)
                            {
                                _followerCardPanels.Add(cPanel);
                            }
                        }
                    }
                }
            }
            else
            {
                //when stock marker is clicked return waste cards to stock
                int j = FindTopCardInPile(new Spot(Card.Pile.Waste)).GetSpot().GetHeight();
                for (int i = j; i > 0; i--)
                {
                    Card?c = FindCardInSpot(new Spot(Card.Pile.Waste, i));
                    c?.SetSpot(new Spot(Card.Pile.Stock, j - i + 1));
                    c?.SetFaceDown();
                }

                Score -= 100;
            }
        }
예제 #2
0
        private void CardDroppedByPlayer(ref CardPanel cardPanelMoved, bool isFollower)
        {
            List <Spot> possibleSpots = GeneratePossibleSpots(cardPanelMoved.GetCard());
            bool        invalidDrop   = true;

            foreach (Spot s in possibleSpots)
            {
                //other card is one below where the new card will be if checks complete successfully
                Card?otherCard = FindCardInSpot(new Spot(s.GetPile(), s.GetHeight() - 1, s.GetColumn()));
                if (otherCard != null)
                {
                    CardPanel?otherCardPanel = FindCardPanelByCard(otherCard);
                    if (otherCardPanel != null)
                    {
                        if (CheckForCardPanelOverlap(cardPanelMoved, otherCardPanel))
                        {
                            //valid move
                            Spot oldSpot = cardPanelMoved.GetCard().GetSpot();
                            cardPanelMoved.GetCard().SetSpot(s);
                            invalidDrop = false;

                            //adds one move if top of cards being moved
                            if (!isFollower)
                            {
                                Moves += 1;
                            }

                            Card topOfOldSpot = FindTopCardInPile(oldSpot);
                            if (topOfOldSpot.GetSpot().GetPile() == Card.Pile.Tableau && !topOfOldSpot.IsMarker)
                            {
                                //reveals card under card moved
                                topOfOldSpot.SetFaceUp();
                            }

                            MoveMade(oldSpot, s);

                            break;
                        }
                    }
                }
            }

            if (invalidDrop)
            {
                cardPanelMoved.UpdateLocation(cardPanelMoved, null);
            }
        }
예제 #3
0
        private Card FindTopCardInPile(Spot spotToCheck)
        {
            Card topInPile;

            switch (spotToCheck.GetPile())
            {
            case Card.Pile.Stock:
                topInPile = _stockMarker.GetCard();
                break;

            case Card.Pile.Waste:
                topInPile = _wasteMarker.GetCard();
                break;

            case Card.Pile.Tableau:
                topInPile = _tableauMarkers[spotToCheck.GetColumn() - 1].GetCard();
                break;

            case Card.Pile.Foundation:
                topInPile = _foundationMarkers[spotToCheck.GetColumn() - 1].GetCard();
                break;

            default:
                return(_stockMarker.GetCard());
                //this is just a fallback, this shouldn't be triggered as player can only move cards to foundation and tableau
            }

            foreach (Card c in _deck)
            {
                if (c.GetSpot().GetPile() == spotToCheck.GetPile() && c.GetSpot().GetColumn() == spotToCheck.GetColumn() && c.GetSpot().GetHeight() > topInPile.GetSpot().GetHeight())
                {
                    topInPile = c;
                }
            }

            return(topInPile);
        }
예제 #4
0
        private void MoveCardToLocation(object sender, EventArgs e)
        {
            const int cardPanelSplitFactor = 3;

            Point     dest;
            CardPanel cardPanelToMove = (CardPanel)sender;
            Card      cardToMove      = cardPanelToMove.GetCard();

            if (_heldCardPanel != null && _followerCardPanels.Contains(cardPanelToMove))
            {
                dest = new Point(_heldCardPanel.Location.X,
                                 _heldCardPanel.Location.Y + (_followerCardPanels.IndexOf(cardPanelToMove) + 1) * CardSize.Height /
                                 cardPanelSplitFactor);
            }
            else
            {
                switch (cardToMove.GetSpot().GetPile())
                {
                case Card.Pile.Stock:
                    dest = _stockMarker.Location;
                    break;

                case Card.Pile.Waste:
                    dest = _wasteMarker.Location;
                    break;

                case Card.Pile.Tableau:
                    dest    = _tableauMarkers[cardToMove.GetSpot().GetColumn() - 1].Location;
                    dest.Y += (cardToMove.GetSpot().GetHeight() - 1) * CardSize.Height / cardPanelSplitFactor;
                    break;

                case Card.Pile.Foundation:
                    dest = _foundationMarkers[(int)cardToMove.GetSuite() - 1].Location;
                    break;

                default:
                    dest = new Point(0, 0);
                    break;
                }
            }

            cardPanelToMove.Location = dest;
            cardPanelToMove.BringToFront();
        }