/* indent:4  tabsize:8  font:fixed-width */


#import "FTSuitDelegate.h"
//#import <Solitaire/Solitaire.h"
#import <Solitaire/CardSet.h>
#import "FortyThieves.h"

@implementation FTSuitDelegate

- (void)setDoubleClickCheck
{
    doubleClickCheck = YES; 
}


- (BOOL) canAcceptPile:(CardPile*)aCardPile from:sender in:(CardPileView*)aCardPileView
{
    Card*	droppingCard = [aCardPile bottomCard];
    Card*   targetCard = [[aCardPileView cardPile] topCard];

    if ([aCardPile cardCount] > 1)
    {
        if (doubleClickCheck)
        {
            droppingCard = [aCardPile topCard];
            doubleClickCheck = NO;
        }
        else
        {
            return NO;
        }
    }

    doubleClickCheck = NO;
    
    if (targetCard)
    {
        if (([droppingCard suit] == [targetCard suit]) &&
                ([droppingCard value] == [targetCard value] + 1))
        {
            return YES;
        }
    }
    else
    {
        if ([droppingCard value] == CS_ACE)
        {
            return YES;
        }
    }
    return NO;
}


- (void) acceptPile:(CardPile*)aCardPile in:(CardPileView*)aCardPileView
{
    [[FortyThieves sharedInstance] checkForWin]; 
}

@end

