Move dup functions to lib.

This commit is contained in:
Murilo Pereira
2011-05-01 03:06:43 -03:00
parent 20d68a6f3d
commit 5d96d20893
12 changed files with 97 additions and 98 deletions

View File

@@ -25,6 +25,20 @@ void initialize_card(struct card *card) {
return;
}
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);
}
void free_card(struct card *card) {
if (card) {
free_frame(card->frame);

View File

@@ -45,6 +45,7 @@ extern const char *program_name;
void allocate_card(struct card **);
void initialize_card(struct card *);
struct card *duplicate_card(struct card *);
void free_card(struct card *);
void set_card(struct card *, enum value, enum suit, enum face, int, int);
void expose_card(struct card *);

View File

@@ -22,6 +22,15 @@ void initialize_frame(struct frame *frame) {
return;
}
struct frame *duplicate_frame(struct frame *frame) {
struct frame *new_frame;
allocate_frame(&new_frame);
set_frame(new_frame, frame->start_y, frame->start_x);
return(new_frame);
}
void free_frame(struct frame *frame) {
if (frame) {
delwin(frame->shape);

View File

@@ -16,6 +16,7 @@ extern const char *program_name;
void allocate_frame(struct frame **);
void initialize_frame(struct frame *);
struct frame *duplicate_frame(struct frame *);
void free_frame(struct frame *);
void set_frame(struct frame *, int, int);

View File

@@ -24,6 +24,25 @@ void initialize_stack(struct stack *stack) {
return;
}
struct stack *duplicate_stack(struct stack *stack) {
struct stack *iterator = stack;
struct stack *tmp_stack, *new_stack;
allocate_stack(&new_stack);
allocate_stack(&tmp_stack);
initialize_stack(new_stack);
initialize_stack(tmp_stack);
for (iterator = stack; iterator; iterator = iterator->next) {
push(&tmp_stack, duplicate_card(iterator->card));
}
while (!empty(tmp_stack)) {
push(&new_stack, (pop(&tmp_stack))->card);
}
free_stack(tmp_stack);
return(new_stack);
}
void free_stack(struct stack *stack) {
struct stack *tmp_stack;

View File

@@ -12,6 +12,7 @@ extern const char *program_name;
void allocate_stack(struct stack **);
void initialize_stack(struct stack *);
struct stack *duplicate_stack(struct stack *);
void free_stack(struct stack *);
bool empty(struct stack *);
int length(struct stack *);