From 90c7ce6280b38251b1d1044f9c50ab94e96a22ef Mon Sep 17 00:00:00 2001 From: Murilo Soares Pereira Date: Tue, 6 Apr 2010 21:59:21 -0300 Subject: [PATCH] delete() for all structures. --- lib/deck.c | 21 +++++++++++++++++++++ lib/deck.h | 3 ++- lib/display.c | 5 +++++ lib/stack.c | 8 +++++++- lib/stack.h | 1 + 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/deck.c b/lib/deck.c index df1f359..59361d3 100644 --- a/lib/deck.c +++ b/lib/deck.c @@ -40,3 +40,24 @@ void initialize_deck(struct deck *deck) { return; } + +void delete_deck(struct deck *deck) { + delete_stack(deck->stock); + + delete_stack(deck->foundation_0); + delete_stack(deck->foundation_1); + delete_stack(deck->foundation_2); + delete_stack(deck->foundation_3); + + delete_stack(deck->maneuvre_0); + delete_stack(deck->maneuvre_1); + delete_stack(deck->maneuvre_2); + delete_stack(deck->maneuvre_3); + delete_stack(deck->maneuvre_4); + delete_stack(deck->maneuvre_5); + delete_stack(deck->maneuvre_6); + + free(deck); + + return; +} diff --git a/lib/deck.h b/lib/deck.h index 4fd2fef..6187440 100644 --- a/lib/deck.h +++ b/lib/deck.h @@ -22,6 +22,7 @@ struct deck { void allocate_deck(struct deck **); void initialize_deck(struct deck *); -//void delete_deck(struct deck *); +void delete_deck(struct deck *); +void shuffle_deck(struct deck *); #endif diff --git a/lib/display.c b/lib/display.c index 6a113dc..b837aff 100644 --- a/lib/display.c +++ b/lib/display.c @@ -42,6 +42,8 @@ void draw_empty_stacks() { delwin(empty_stack[i]); } + free(empty_stack); + return; } @@ -49,6 +51,9 @@ void initialize_game() { struct deck *deck = NULL; draw_empty_stacks(); + allocate_deck(&deck); + initialize_deck(deck); + delete_deck(deck); return; } diff --git a/lib/stack.c b/lib/stack.c index cf0df7c..e42cacc 100644 --- a/lib/stack.c +++ b/lib/stack.c @@ -11,12 +11,18 @@ void allocate_stack(struct stack **stack) { } void initialize_stack(struct stack *stack) { - stack->card = NULL; stack->next = NULL; return; } +void delete_stack(struct stack *stack) { + delete_card(stack->card); + free(stack); + + return; +} + bool empty(struct stack *stack) { return(stack->card == NULL); } diff --git a/lib/stack.h b/lib/stack.h index 505ccf4..2f3a79b 100644 --- a/lib/stack.h +++ b/lib/stack.h @@ -10,6 +10,7 @@ struct stack { void allocate_stack(struct stack **); void initialize_stack(struct stack *); +void delete_stack(struct stack *); bool empty(struct stack *); int length(struct stack *); void push(struct stack **, struct card *);