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

#import "FTDiscardPileDelegate.h"
#import "FTSuitDelegate.h"
#import "../Solitaire/Solitaire.h"
#import "FortyThieves.h"

@implementation FTDiscardPileDelegate

- setSuitCardPileViews:(id [])theViews
{
    int i;
    
    for (i=0; i<8; i++)
        suitCardPileViews[i] = *(theViews + i);

    return self;
}


- doubleClickedCard:aCard in:aCardPileView
{
    int i;
    
    id	cardPile = [aCardPileView cardPile];
    
    if ((aCard == [cardPile cardAt:CS_TOP] ) && (![aCard isFaceUp]))
    {
	[aCard flip];
	[aCardPileView display];
    }
    else if (aCard == [cardPile cardAt:CS_TOP])
    {
	for (i=0;i<8;i++)
	{
	    [[suitCardPileViews[i] delegate] setDoubleClickCheck];
	    if ([[suitCardPileViews[i] delegate] canAcceptPile:cardPile
	                                      from:aCardPileView
	                                        in:suitCardPileViews[i]])
	    {
		[[suitCardPileViews[i] cardPile] addCard:[cardPile
		                                           cardAt:CS_TOP]];
		[cardPile removeCard:[cardPile cardAt:CS_TOP]];
		[aCardPileView display];
		[suitCardPileViews[i] display];
		[SolGameController() checkForWin];
		break;
	    }
	}
    }
    return self;
}


- (BOOL)draggedPile:aCardPile from:discardCardPileView
{
    id discardCardPile = [discardCardPileView cardPile];

    if (([aCardPile cardAt:CS_TOP]) == ([discardCardPile cardAt:CS_TOP]))
    {
	return YES;
    }
    return NO;
}


- getOffset:(float *) xOffset :(float *) yOffset forSize:(CardSize)aSize
{
    if (aSize == CS_SMALL)
    {
    	*xOffset = 12.0;
    }
    else
    {
	*xOffset = 16.0;
    }    
    *yOffset = 0.0;
    return self;
}

@end
