Пример #1
0
// translate the card value to a string.
// return the number of characters written to pRank, excluding
// the terminating '\0'.
int CCard::translateCard(char* pRank, char* pSuit) const
{
	int numChars;

	if (getFaceUp()) {
		// card is visible so print rank and suit
		numChars = sprintf(pSuit, "%c", (char)getSuit());
		pSuit[numChars] = '\0';

		numChars = getCharRank(pRank, 3);
		pRank[numChars] = '\0';
	}
	else {
		// card is not visible so display as ###
		strcpy(pSuit, "#");
		numChars = 1;
		pSuit[numChars] = '\0';

		strcpy(pRank, "##");
		numChars = 2;
		pRank[numChars] = '\0';
	}

	return(numChars);
}
Пример #2
0
uint8_t readNextCard(uint32_t * const endOfFile) {
    uint32_t haveCardValue,haveSuitValue,haveRankValue;
    uint8_t  cardValue = 0;
    int  c;
    haveCardValue = haveSuitValue = haveRankValue = 0;
    *endOfFile = 0;
    while(!(*endOfFile) && !haveCardValue && (c=getchar())) {
        switch(c) {
        case EOF :
            *endOfFile = 1;
            break;
        /* Ignore WhiteSpace */
        case ' ' :
        case '\n':
        case '\t':
        case '\v':
            break;
        /* Parse Suit Tokens */
        case 'H' :
        case 'D' :
        case 'S' :
        case 'C' :
            if(!haveSuitValue) cardValue |= getCharSuit(c);
            haveSuitValue = 1;
            break;
        /* Parse Rank Tokens */
        case '2' :
        case '3' :
        case '4' :
        case '5' :
        case '6' :
        case '7' :
        case '8' :
        case '9' :
        case 'T' :
        case 'J' :
        case 'Q' :
        case 'K' :
        case 'A' :
            if(!haveRankValue) cardValue |= getCharRank(c);
            haveRankValue = 1;
            break;
        default:
            break;
        }
        haveCardValue = haveSuitValue && haveRankValue;
    }
    return cardValue;
}