This is Hand.m in view mode; [Download] [Up]
// Hand.m // Project: Cribbage // Stephan Wacker // 93-09-16 #import "Hand.h" @implementation Hand - emptyHand { int i; for( i = 0; i < FULLHAND; i++ ) { hand[i].rank = hand[i].suit = EMPTY; face[i] = FACE_NONE; } nHand = 0; return self; } - addCard: (CARD) aCard faceUp: (BOOL) f // // Add aCard to the hand. // { hand[ nHand ] = aCard; face[ nHand ] = (f ? FACE_UP : FACE_DOWN); ++ nHand; return self; } - sortHand // // Sort the cards by rank and suit. // Simple selection sort. // { int i, j; CARD c; FACE f; for( i = 0; i < nHand; i++ ) { for( j = i+1; j < nHand; j++ ) { if( (hand[j].rank < hand[i].rank) || ( hand[j].rank == hand[i].rank && hand[j].suit < hand[i].suit) ) { c = hand[i], f = face[i]; hand[i] = hand[j], face[i] = face[j]; hand[j] = c, face[j] = f; } } } return self; } @end // Hand
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.