private Card?FindCardInSpot(Spot targetSpot) { //note: 2 cards should never share an identical spot foreach (CardPanel cPanel in GetAllCardPanels()) { Card c = cPanel.GetCard(); if (c.GetSpot().GetPile() == targetSpot.GetPile() && c.GetSpot().GetHeight() == targetSpot.GetHeight() && c.GetSpot().GetColumn() == targetSpot.GetColumn()) { return(c); } } //if no card in target spot then return null return(null); }
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(); }
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); } }