// This draw routine assumes that pSprite->Begin() called before and // pSprite->End() is called after. HRESULT CCard::draw(ID3DX10Sprite * pSprite, D3DX10_SPRITE* pSpriteArray) const { HRESULT hResult = S_OK; D3DXMATRIXA16 matScaling; D3DXMATRIXA16 matTranslation; // Add one to width since right border of card is not displaying D3DXMatrixScaling( &matScaling, (float)getSpriteWidth()+1, (float)getSpriteLength(), 1.0f ); // (0, 0) is lower left corner D3DXMatrixTranslation( &matTranslation, (float)getLocation().x, (float)getLocation().y, 0.1f); pSpriteArray->matWorld = matScaling * matTranslation; pSpriteArray->TexCoord.x = 0.0f; pSpriteArray->TexCoord.y = 0.0f; pSpriteArray->TexSize.x = 1.0f; pSpriteArray->TexSize.y = 1.0f; pSpriteArray->ColorModulate = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f); if (getFaceUp()) { pSpriteArray->pTexture = getFrontTexture(); } else { pSpriteArray->pTexture = getBackTexture(); } pSpriteArray->TextureIndex = 0; return(hResult); }
// 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); }
std::string Card::toString() const { //Nothing should be able to know about face down cards. if(!getFaceUp()) return "Face down card"; std::stringstream toRet; if(number < 11 && number > 1) toRet << number << " of " << suitToString(suit); else { if(number == 1) toRet << "Ace of " << suitToString(suit); if(number == 11) toRet << "Jack of " << suitToString(suit); if(number == 12) toRet << "Queen of " << suitToString(suit); if(number == 13) toRet << "King of " << suitToString(suit); } return toRet.str(); }