This is CardPile.rtf in view mode; [Download] [Up]
paperh18648 margl-907 margr0 margt0 margb0fi0 ri0 ql sb0 f1 fs24 Copyright f3 'e3f1 1998 All Rights Reserved. i i0 s5 li2116 fi0 ri1007 ql f0 fs56 b CardPileb0 {fs16 }s17 li4888 fi-2771 ri1007 ql tx4888 f0 fs28 b Inherits From:b0 f1 fs28 NSObject s17 li4888 fi-2771 ri1007 ql tx4888 f0 fs28 b Declared In:b0 f1 fs28 CardPile.h s13 li1360 fi0 ri1007 ql fs16 f0 fs36 b Class Descriptionb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Instances of this class provide low-level functionality for card games. CardPiles contain an ordered list of Card objects which can be added to, removed from, or shuffled by clients of the class. s13 li1360 fi0 ri1007 ql fs16 f0 fs36 b Symbolic Constantsb0 {fs16 }tx2116 tx6148 tx6794 tx7440 tx8086 tx9378li6148 fi-4421 fc0 cf0 f0 fs20 b SYNOPSISb0 s11 li6148 fi-4031 ri1007 ql tx7440 tx8086 tx8732 tx9378 tx10024 tx10670f1 fs28 CS_BOTTOM0 0 CS_TOP0 9999 s13 li1360 fi0 ri1007 ql fs16 f0 fs36 b Instance Variablesb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 NSMutableArray* b cardsb0 ; CardSize b cardSizeb0 ; s11 li6148 fi-4031 ri1007 ql tx6148 f1 fs28 cards Our cards. s11 li6148 fi-4031 ri1007 ql tx6148 f1 fs28 cardSize Our card size. s13 li1360 fi0 ri1007 ql fs16 f0 fs36 b Method Typesb0 {fs16 }s11 li6148 fi-4031 ri1007 ql tx6148 f1 fs28 Class initialization + initialize Initialization/deallocation {f3 -} init {f3 -} initForCardSize: {f3 -} setCardSize: {f3 -} cardSize {f3 -} dealloc Manipulating cards {f3 -} addCard: {f3 -} insertCard:at: {f3 -} addPile: {f3 -} addCopyOfPile: {f3 -} insertCopyOfPile:at: {f3 -} insertPile:at: {f3 -} removeCard: {f3 -} cardAtIndex: {f3 -} indexOfCard: {f3 -} topCard {f3 -} bottomCard {f3 -} dealTopCard Manipulating the deck {f3 -} addDeck {f3 -} empty {f3 -} flip {f3 -} shuffle {f3 -} cardCount Archiving {f3 -} initWithCoder: {f3 -} encodeWithCoder: s13 li1360 fi0 ri1007 ql fs16 f0 fs36 b Class Methodsb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b initializeb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 + (void)b initializeb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Sets a random seed based on the time before initializing the class. s13 li1360 fi0 ri1007 ql fs16 f0 fs36 b Instance Methodsb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b addCard:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b addCardb0 b :b0 (Card*)i aCardi0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Adds i aCardi0 to the top of our deck. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b addCopyOfPile:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b addCopyOfPileb0 b :b0 (CardPile*)i aCardPilei0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Acts as a cover for b insertCopyOfCardPile:at:b0 , but always adds cards to the top of a pile. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b addDeckb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b addDeckb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Adds a full deck of cards to the top of the pile, neatly ordered. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b addPile:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b addPileb0 b :b0 (CardPile*)i aCardPilei0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Adds i aCardPilei0 to the top of our cards we already have. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b bottomCardb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (Card*)b bottomCardb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Returns our bottom card or b nilb0 if we don't have any cards. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b cardAtIndex:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (Card*)b cardAtIndexb0 b :b0 (int)i aPositioni0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Allow a client to find out what card is at a given position in the pile. The constants CS_TOP and CS_BOTTOM can be used to specify the top and bottom of the pile, respectively. If i aPositioni0 is less than zero or larger the number of cards we have, b nilb0 is returned. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b cardCountb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (int)b cardCountb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Returns the number of cards in our pile. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b cardSizeb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (CardSize)b cardSizeb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Returns the current size of our cards. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b dealTopCardb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (Card*)b dealTopCardb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Removes our top card from the deck and returns it. If we don't have any cards then b nilb0 is returned. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b deallocb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b deallocb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Releases our resources (our cards). pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b emptyb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b emptyb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Removes all our cards. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b encodeWithCoder:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b encodeWithCoderb0 b :b0 (NSCoder *)i aCoderi0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Archives a CardPile instance. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b flipb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b flipb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Turns the pile over, reversing the order of the cards and the orientation of each card. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b indexOfCard:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (int)b indexOfCardb0 b :b0 (Card*)i aCardi0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Returns the index of i aCardi0 if it is in our pile. If not then NSNotFound is returned. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b initb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 b initb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Calls our designated initializer b initForCardSize:b0 with CS_SMALL as the argument. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b initForCardSize:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 b initForCardSizeb0 b :b0 (CardSize)i aSizei0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Our designated initializer. i aSizei0 can be one of CS_SMALL or CS_LARGE, for small or large cards. The new pile will contain no cards. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b initWithCoder:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (id)b initWithCoderb0 b :b0 (NSCoder *)i aDecoderi0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Unarchives a CardPile instance. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b insertCard:at:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b insertCardb0 b :b0 (Card*)i aCardi0 b atb0 b :b0 (int)i aPositioni0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Adds a card to the pile at the specified position. The constants CS_TOP and CS_BOTTOM can be used to specify the top and bottom of the pile. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b insertCopyOfPile:at:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b insertCopyOfPileb0 b :b0 (CardPile*)i aCardPilei0 b atb0 b :b0 (int)i aPositioni0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Adds another pile of cards to this pile at a specific position. The constants CS_TOP and CS_BOTTOM can be used to specify the top and bottom of the pile, respectively. The cards added are copies of (and independent from) the source cards. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b insertPile:at:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b insertPileb0 b :b0 (CardPile*)i aCardPilei0 b atb0 b :b0 (int)i aPositioni0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Adds another pile of cards to this pile at a specific position. The constants CS_TOP and CS_BOTTOM can be used to specify the top and bottom of the pile, respectively. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b removeCard:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b removeCardb0 b :b0 (Card*)i aCardi0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Remove a specific card from the pile. The card's retain count will drop by one. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b setCardSize:b0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b setCardSizeb0 b :b0 (CardSize)i aSizei0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Sets our card size. It should be one of CS_SMALL or CS_LARGE. If the current cards are of a different size than i aSizei0 they'll all be resized and recached. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b shuffleb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (void)b shuffleb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Randomly re-order all card objects contained in the pile. pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 f0 fs28 b topCardb0 fs28 {fs8 }tx3240 li2100 fi-760 li3240f1 fs28 (Card*)b topCardb0 {fs16 }pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 Returns our top card or b nilb0 if we don't have any cards.
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.