This is StockCardPileDelegate.m in view mode; [Download] [Up]
/* indent:4 tabsize:8 font:fixed-width */ #import "StockCardPileDelegate.h" #import <Solitaire/CardSet.h> #import "Pyramid.h" #import "localstrings.h" #import "AlertPanel.h" @implementation StockCardPileDelegate /*---------------------------------------------------------------------------- | | Delegate-setting methods | \---------------------------------------------------------------------------*/ - (void) setDiscardLeft:(CardPileView*)left discardRight:(CardPileView*)right waste:(CardPileView*)waste { discardCardPileViewL = left; discardCardPileViewR = right; wasteCardPileView = waste; } /*-------------------------------------------------------------------------- | | - clickedCard:aCard in:stockCardPileView | |--------------------------------------------------------------------------- | | Called by the StockPileCardView when the mouse is clicked on the pile. | \---------------------------------------------------------------------------*/ - (void) clickedCard:(Card*)aCard in:(CardPileView*)stockCardPileView { CardPile* wasteCardPile = [wasteCardPileView cardPile]; CardPile* stockCardPile = [stockCardPileView cardPile]; /*----------------------------------------------------------------------- | | If the stock pile is empty, turn over the waste pile | and move the cards pack to the stock pile. | \-----------------------------------------------------------------------*/ if (!aCard) { /*----------------------------------------------------------------- | | The pile may not actually be empty; the user may | have clicked on an exposed area of the pile view. | \----------------------------------------------------------------*/ if ([stockCardPile cardCount] > 0) { return; } if ([[Pyramid sharedInstance] dealCount] < 3) { [wasteCardPile flip]; [stockCardPile addPile:wasteCardPile]; [wasteCardPile empty]; [wasteCardPileView display]; [stockCardPileView display]; [[Pyramid sharedInstance] incDealCount]; } else { NSRunAlertPanel(LOCALIZED_GAME_NAME, LOCALIZED_NO_FLIP, @"", nil, nil); return; } } else /*----------------------------------------------------------------- | | If the top card was clicked, and it was face-down, | turn it face-up. Then, move it to the waste pile. | If this card and the card currently on top of the waste | pile add to 13, give the user the option to leave it on | the waste pile, or to discard them both. \---------------------------------------------------------------*/ if ((aCard == [stockCardPile topCard]) && (![aCard isFaceUp])) { Card* wasteCard = [wasteCardPile topCard]; [aCard flip]; [stockCardPileView display]; if (wasteCard && ([aCard value] + [wasteCard value] == 11)) { int result; [[alertPanel first] setTitle:LOCALIZED_LEAVE_ON_WASTE]; [[alertPanel second] setTitle:LOCALIZED_REMOVE_THEM]; [[alertPanel message] setStringValue:LOCALIZED_TURN_MATCH]; [[alertPanel alert] setStringValue:LOCALIZED_GAME_NAME]; [alertPanel run:self]; result = [alertPanel lastResult]; if (result == NSAlertAlternateReturn) { CardPile* leftDiscardPile = [discardCardPileViewL cardPile]; CardPile* rightDiscardPile = [discardCardPileViewR cardPile]; [aCard retain]; [stockCardPile removeCard:aCard]; [leftDiscardPile addCard:aCard]; [aCard release]; [wasteCard retain]; [wasteCardPile removeCard:wasteCard]; [rightDiscardPile addCard:wasteCard]; [wasteCard release]; [discardCardPileViewL display]; [discardCardPileViewR display]; [stockCardPileView display]; [wasteCardPileView display]; [[Pyramid sharedInstance] checkForWin]; return; } } [aCard retain]; [stockCardPile removeCard:aCard]; [wasteCardPile addCard:aCard]; [aCard release]; [stockCardPileView display]; [wasteCardPileView display]; [[Pyramid sharedInstance] checkForWin]; } } /*-------------------------------------------------------------------------- | | - (BOOL) canAcceptPile:aCardPile from:sender in:stockCardPileView | | returns:(BOOL) YES if this pile will accept the cards dropped on it | | (BOOL) NO if this pile will not accept the dropped cards | |--------------------------------------------------------------------------- | | Called by the StockPileCardView when a card pile wants to be dropped | on this pile. | \--------------------------------------------------------------------------*/ - (BOOL) canAcceptPile:(CardPile*)aCardPile from:sender in:(CardPileView*)stockCardPileView { return NO; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.