Exemplo n.º 1
0
/**
 * Draws the card to the screen at it's location
 */
void GraphicalCard::draw() {
	int x = 2, y = 4;
	if (is_faceup()) {
		x = get_rank() - 1;
		y = get_suit();
	}
	draw_bitmap_part(_spritesheet, x*CARD_WIDTH, y*CARD_HEIGHT, CARD_WIDTH, CARD_HEIGHT, _position.x, _position.y);
}
Exemplo n.º 2
0
/**
 * renders a card to a pair of characters
 * Queen Diamonds -> QD 
 * 2 Spades -> 2S
 * it'd be nice to use the actual suit symbols but then we'd need 
 * to print wide chars
 */
void card_to_str_short(int card, char* buffer)
{
  assert(card >= 0 && card < NSUITS*NTYPES);

  char type = type_to_char(get_type(card));
  char suit = suit_to_char(get_suit(card));

  sprintf(buffer, "%c%c", type, suit);
}
Exemplo n.º 3
0
/** 
 * renders a card to a space separated string like 
 * Ace Clubs, or 2 Spades 
 */
void card_to_str_long(int card, char* buffer)
{
  assert(card >= 0 && card < NSUITS*NTYPES);

  char type_buffer[16];
  char suit_buffer[16];
  type_to_str(get_type(card), type_buffer);
  suit_to_str(get_suit(card), suit_buffer);  

  sprintf(buffer, "%s %s", type_buffer, suit_buffer);
}
char * card_to_string(char * s, int card, int not_append_ws)
{
    int suit = get_suit(card);
    int v = get_value(card);

    if (v == 1)
    {
        strcpy(s, "A");
    }
    else if (v <= 10)
    {
        sprintf(s, "%i", v);
    }
    else
    {
        strcpy(s, (v == 11)?"J":((v == 12)?"Q":"K"));
    }

    switch (suit)
    {
        case 0:
            strcat(s, "S");
            break;
        case 1:
            strcat(s, "C");
            break;
        case 2:
            strcat(s, "H");
            break;
        case 3:
            strcat(s, "D");
            break;
    }

    if (!not_append_ws)
    {
        strcat(s, " ");
    }

    return s;
}