Beispiel #1
0
/**
 * RenderHouseCards: Renders cards of the house
 * \param _house vector with the house cards
 * \param _pos_house_hand position of the vector _house with valid card IDs
 * \param _cards vector with all loaded card images
 * \param _renderer renderer to handle all rendering in a window
 */
void RenderHouseCards(Player *house, SDL_Surface **_cards, TTF_Font *_font, SDL_Renderer* _renderer)
{
    int x = 0, y = 0;
    int div = WIDTH_WINDOW/CARD_WIDTH;
	Card *cur_card = NULL;
	int card_id = 0;
	int num_cards = 0;
    SDL_Color white = { 255, 255, 255, 255};
	char status_str[STRING_SIZE] = {0};
	char points_str[STRING_SIZE] = {0};

	if (house->status == WW || house->status == ST)
		sprintf(points_str, "%d", house->points);
	else if (house->status == BJ)
		sprintf(points_str, "BJ");
	else if (house->status == BU)
		sprintf(points_str, "BU");

	sprintf(status_str, "dealer: %s points", points_str);
	RenderText(20, 130, status_str, _font, &white, _renderer);

    Stack *aux = house->cards;
    Stack *tmp = NULL;
    // drawing all house cards
	while (tmp != house->cards) {
		aux = house->cards;
        while (aux->next != tmp)
            aux = aux->next;

		cur_card = aux->card;
		card_id = cur_card->id + cur_card->suit * SUIT_SIZE;

        // calculate its position
        x = (div/2 - house->num_cards/2 + num_cards)*CARD_WIDTH + 15;
        y = (int) (0.26f*HEIGHT_WINDOW);
        RenderCard(x, y, card_id, _cards, _renderer);

		num_cards++;
        tmp = aux;
    }

    // If the dealer has only 2 cards and no blackjack, draw the second card face down
    if (house->num_cards == 1 && house->status != BJ) {
        x = (div/2-house->num_cards/2+1)*CARD_WIDTH + 15;
        y = (int) (0.26f*HEIGHT_WINDOW);
        RenderCard(x, y, MAX_DECK_SIZE, _cards, _renderer);
    }
}
Beispiel #2
0
void CGeneral::DrawCard(const CCard &c, int x, int y, int w, int h, bool update)
{
   SDL_Surface *p = RenderCard(c, w, h);
   SDL_Rect dstrect;

   dstrect.x = x;
   dstrect.y = y;
   dstrect.w = w;
   dstrect.h = h;

   SDL_BlitSurface(p, NULL, gpScreen, &dstrect);
   SDL_FreeSurface(p);

   if (update) {
      UpdateScreen(x, y, dstrect.w, dstrect.h);
   }
}
Beispiel #3
0
/**
 * RenderPlayerCards: Renders the hand, i.e. the cards, for each player
 * \param _player_cards 2D array with the player cards, 1st dimension is the player ID
 * \param _pos_player_hand array with the positions of the valid card IDs for each player
 * \param _cards vector with all loaded card images
 * \param _renderer renderer to handle all rendering in a window
 */
void RenderPlayerCards(List *players, SDL_Surface **_cards, SDL_Renderer* _renderer)
{
    int pos = 0, x = 0, y = 0;
    int num_player = 0;
    int num_cards = 0;
    int card_id = 0;

    List *aux = players->next; // dummy head
    Player *cur_player = NULL;
    Card *cur_card = 0;
	Stack *aux_cards = NULL;
    // Iterate over all players
    while (aux) {
        cur_player = (Player *) aux->payload;
		if (cur_player->ingame) {
			// Iterate over the stack backwards
			aux_cards = cur_player->cards;
			if (aux_cards)
				while (aux_cards->next)
					aux_cards = aux_cards->next;

			// agora aux_cards aponta para o último elemento da stack
			while (aux_cards) {
				// get the card
				cur_card = aux_cards->card;
				card_id = cur_card->id + cur_card->suit * SUIT_SIZE;

				// draw the card
				pos = num_cards % 4;
				x = (int) num_player * (SEP/4-5)+(num_cards/4)*12+15;
				y = (int) PLAYER_RECT_Y+10;
				if ( pos == 1 || pos == 3) x += CARD_WIDTH + 30;
				if ( pos == 2 || pos == 3) y += CARD_HEIGHT+ 10;
				RenderCard(x, y, card_id, _cards, _renderer);

				num_cards++;
				aux_cards = aux_cards->prev;
			}
			num_cards = 0;
		}
		aux = aux->next;
		num_player++;
    }
}