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


#import "TenpileTempDelegate.h"
#import "TenpileSuitDelegate.h"
//#import <Solitaire/Solitaire.h"
#import <Solitaire/CardSet.h>
#import "Tenpile.h"

@implementation TenpileTempDelegate

- (void) setSuitCardPileViews:(id [])theViews
{
    int i;

    for (i=0; i<4; i++) {
        suitCardPileViews[i] = *(theViews + i);
    }
}
    

- (void) doubleClickedCard:(Card*)aCard in:(CardPileView*)aCardPileView
{
    int i;
    
    CardPile* cardPile = [aCardPileView cardPile];
    
    if ((aCard == [cardPile topCard]) && (![aCard isFaceUp]))
    {
        [aCard flip];
        [aCardPileView display];
    }
    else if (aCard == [cardPile topCard])
    {
        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 topCard]];
                [cardPile removeCard:[cardPile topCard]];
                [aCardPileView display];
                [suitCardPileViews[i] display];
                [[Tenpile sharedInstance] checkForWin];

                break;
            }
        }
    } 
}


- (BOOL) canAcceptPile:(CardPile*)aCardPile from:sender in:(CardPileView*)aCardPileView
{
    if ([[aCardPileView cardPile] cardCount] == 0 && [aCardPile cardCount] == 1)
	{
	    return YES;
	}
    return NO;
}


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

@end

