2011-02-06 05:44:45 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2010-04-01 05:28:00 +00:00
|
|
|
#include <malloc.h>
|
2011-02-06 05:44:45 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2010-04-03 04:20:49 +00:00
|
|
|
#include "card.h"
|
2010-04-01 05:28:00 +00:00
|
|
|
|
2010-04-05 07:33:10 +00:00
|
|
|
void allocate_card(struct card **card) {
|
2011-02-06 05:44:45 +00:00
|
|
|
if (!(*card = malloc(sizeof(**card)))) {
|
|
|
|
fprintf(stderr, "%s: %s (%s:%d)\n", program_name, strerror(errno), __FILE__, __LINE__ - 1);
|
|
|
|
exit(errno);
|
|
|
|
}
|
2010-04-01 05:28:00 +00:00
|
|
|
|
2010-04-05 07:33:10 +00:00
|
|
|
allocate_frame(&((*card)->frame));
|
|
|
|
}
|
|
|
|
|
|
|
|
void initialize_card(struct card *card) {
|
|
|
|
initialize_frame(card->frame);
|
2011-02-10 01:25:28 +00:00
|
|
|
card->value = NO_VALUE;
|
|
|
|
card->suit = NO_SUIT;
|
|
|
|
card->face = NO_FACE;
|
2010-04-01 05:28:00 +00:00
|
|
|
}
|
|
|
|
|
2011-05-01 06:06:43 +00:00
|
|
|
struct card *duplicate_card(struct card *card) {
|
|
|
|
struct card *new_card;
|
|
|
|
|
|
|
|
allocate_card(&new_card);
|
|
|
|
set_card(new_card,
|
|
|
|
card->value,
|
|
|
|
card->suit,
|
|
|
|
card->face,
|
|
|
|
card->frame->start_y,
|
|
|
|
card->frame->start_x);
|
|
|
|
|
|
|
|
return(new_card);
|
|
|
|
}
|
|
|
|
|
2011-02-14 02:10:47 +00:00
|
|
|
void free_card(struct card *card) {
|
2011-02-12 03:26:03 +00:00
|
|
|
if (card) {
|
2011-02-14 02:10:47 +00:00
|
|
|
free_frame(card->frame);
|
2011-02-12 03:26:03 +00:00
|
|
|
}
|
2010-04-01 05:28:00 +00:00
|
|
|
free(card);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_card(struct card *card,
|
|
|
|
enum value value,
|
|
|
|
enum suit suit,
|
2010-04-01 12:50:53 +00:00
|
|
|
enum face face,
|
2010-04-01 05:28:00 +00:00
|
|
|
int start_y,
|
|
|
|
int start_x) {
|
|
|
|
set_frame(card->frame, start_y, start_x);
|
|
|
|
card->value = value;
|
|
|
|
card->suit = suit;
|
2010-04-01 12:50:53 +00:00
|
|
|
card->face = face;
|
2010-04-01 05:28:00 +00:00
|
|
|
}
|
2010-04-10 03:45:54 +00:00
|
|
|
|
|
|
|
void expose_card(struct card *card) {
|
|
|
|
card->face = EXPOSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cover_card(struct card *card) {
|
|
|
|
card->face = COVERED;
|
|
|
|
}
|