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


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

@implementation TenpileTempDelegate

- setSuitCardPileViews:(id [])theViews
{
    int i;
    
    for (i=0; i<4; 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 < 4; 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)canAcceptPile:aCardPile from:sender in:aCardPileView
{
    if ([[aCardPileView cardPile] cardCount] == 0
	&& [aCardPile cardCount] == 1)
	{
	    return YES;
	}
    return NO;
}


- (BOOL)draggedPile:aCardPile from:aCardPileView
{
    return YES;
}


@end
