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


#import "TenpileSuitDelegate.h"
#import "../Solitaire/Solitaire.h"
#import "../Solitaire/CardSet.subproj/cardset.h"
#import "Tenpile.h"

@implementation TenpileSuitDelegate

- setDoubleClickCheck
{
    doubleClickCheck = YES;
    return self;
}


- (BOOL)canAcceptPile:aCardPile from:sender in:aCardPileView
{
    id        droppingCard = [aCardPile cardAt:CS_BOTTOM];
    id        targetCard = [[aCardPileView cardPile] cardAt:CS_TOP];

    if ([aCardPile cardCount] > 1)
    {
        if (doubleClickCheck)
        {
            droppingCard = [aCardPile cardAt:CS_TOP];
            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;
}


- acceptPile:aCardPile in:aCardPileView
{
    [SolGameController() checkForWin];
    return self;
}

@end
