private bool PerformMove(Card from, Card to) { if (from != null && to != null) { _game.LastMove = new Move(from, to); _game.ExecuteMove(from, to); return true; } return false; }
public Card FindIntersectingGap(Card movedCard) { foreach (Card targetCard in Deck.Where(c => c.Value == Value.Ace)) { Rect targetRect = targetCard.Bounds; targetRect.Intersect(movedCard.Bounds); if (!targetRect.IsEmpty && MoveAllowed(movedCard, targetCard)) { return targetCard; } } return null; }
public bool MoveAllowed(Card from, Card to) { if (from.Value != Value.Ace && to.Value == Value.Ace) { int index = Deck.IndexOf(to); if (index%13 == 0 && from.Value == Value.Two) { return true; } if (from.Value != Value.Two && Deck[index - 1].Suit == from.Suit && Deck[index - 1].Value == from.Value - 1) { return true; } } return false; }
public Card FindGapForCard(Card card) { if (card.Value == Value.Two) { for (int i = 0; i < Deck.Count; i += 13) { if (Deck[i].Value == Value.Ace) { return Deck[i]; } } } else { for (int i = 0; i < Deck.Count; i++) { if (Deck[i].Suit == card.Suit && Deck[i].Value == card.Value - 1) { if (i < Deck.Count - 1 && Deck[i + 1].Value == Value.Ace && (i + 1)%13 != 0) { return Deck[i + 1]; } } } } return null; }
public List<Card> FindCardsForGap(Card gap) { int index = Deck.IndexOf(gap); var cards = new List<Card>(); if (index%13 == 0) { cards.AddRange(Deck.Where(c => c.Value == Value.Two)); } else if (Deck[index - 1].Value != Value.King && Deck[index - 1].Value != Value.Ace) { cards.Add(Deck.First(c => c.Suit == Deck[index - 1].Suit && c.Value == Deck[index - 1].Value + 1)); } return cards; }
public void ExecuteMove(Card from, Card to) { Deck.Swap(Deck.IndexOf(from), Deck.IndexOf(to)); from.ExecuteMove(to); Moves++; }
public Deal(Card card, Point source, Point target) { Card = card; Source = source; Target = target; }
public void ExecuteMove(Card target) { Point temp = (IsMouseCaptured ? Original : Location); Animate(Location, target.Location, true); target.Location = temp; }