Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 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;
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
 public void ExecuteMove(Card from, Card to)
 {
     Deck.Swap(Deck.IndexOf(from), Deck.IndexOf(to));
     from.ExecuteMove(to);
     Moves++;
 }
Exemplo n.º 7
0
 public Deal(Card card, Point source, Point target)
 {
     Card = card;
     Source = source;
     Target = target;
 }
Exemplo n.º 8
0
 public void ExecuteMove(Card target)
 {
     Point temp = (IsMouseCaptured ? Original : Location);
     Animate(Location, target.Location, true);
     target.Location = temp;
 }