Esempio n. 1
0
        private CardPanel[] GetAllCardPanels()
        {
            CardPanel[] result = new CardPanel[65];

            int i = 0;

            result[i] = _stockMarker;
            i++;
            result[i] = _wasteMarker;
            i++;
            foreach (CardPanel tMarker in _tableauMarkers)
            {
                result[i] = tMarker;
                i++;
            }
            foreach (CardPanel fMarker in _foundationMarkers)
            {
                result[i] = fMarker;
                i++;
            }
            foreach (CardPanel cMarker in _cardPanels)
            {
                result[i] = cMarker;
                i++;
            }

            return(result);
        }
Esempio n. 2
0
        private void CreateCardPanels()
        {
            _cardPanels = new CardPanel[52];

            for (int i = 0; i < 52; i++)
            {
                _cardPanels[i] = new CardPanel(ref _deck[i]);
            }
        }
Esempio n. 3
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;
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        private void CreateMarkers()
        {
            //stock and waste markers
            _stockMarkerCard = new Card(0, Card.Suites.None, new Spot(Card.Pile.Stock), true);
            _stockMarker     = new CardPanel(ref _stockMarkerCard)
            {
                Location = GetPlayAreaLocation(10, 10)
            };

            _wasteMarkerCard = new Card(0, Card.Suites.None, new Spot(Card.Pile.Waste), true);
            _wasteMarker     = new CardPanel(ref _wasteMarkerCard)
            {
                Location = GetPlayAreaLocation(10, 30)
            };


            //tableau markers
            _tableauMarkerCards = new Card[7];
            _tableauMarkers     = new CardPanel[7];

            for (int i = 0; i < 7; i++)
            {
                _tableauMarkerCards[i] = new Card(14, Card.Suites.None, new Spot(Card.Pile.Tableau, 0, i + 1), true);
                _tableauMarkers[i]     = new CardPanel(ref _tableauMarkerCards[i])
                {
                    Location = GetPlayAreaLocation(25 + i * 5, 10)
                };
            }


            //foundation markers
            _foundationMarkerCards = new Card[4];
            _foundationMarkers     = new CardPanel[4];

            for (int i = 0; i < 4; i++)
            {
                _foundationMarkerCards[i] = new Card(0, (Card.Suites)i + 1, new Spot(Card.Pile.Foundation, 0, i + 1), true);
                _foundationMarkers[i]     = new CardPanel(ref _foundationMarkerCards[i])
                {
                    Location = GetPlayAreaLocation(80, 10 + 20 * i)
                };
            }
        }
Esempio n. 7
0
 private bool CheckForCardPanelOverlap(CardPanel panel1, CardPanel panel2)
 {
     return(!((panel1.Left > panel2.Right || panel1.Top > panel2.Bottom) ||
              (panel2.Left > panel1.Right || panel2.Top > panel1.Bottom)));
 }