diff --git a/lib/cursor.c b/lib/cursor.c index 3469fe9..d6a34cf 100644 --- a/lib/cursor.c +++ b/lib/cursor.c @@ -1,7 +1,5 @@ #include #include -#include "stack.h" -#include "deck.h" #include "display.h" #include "game.h" #include "cursor.h" diff --git a/lib/cursor.h b/lib/cursor.h index 93510c5..28af2b7 100644 --- a/lib/cursor.h +++ b/lib/cursor.h @@ -2,6 +2,7 @@ #define CURSOR_H #include +#include "deck.h" #define CURSOR_STARTING_X 4 #define CURSOR_STARTING_Y 7 diff --git a/lib/display.c b/lib/display.c index 8080385..fb09c23 100644 --- a/lib/display.c +++ b/lib/display.c @@ -46,6 +46,22 @@ char *card_value(enum value value) { return(card_value); } +void erase_stack(struct stack *stack) { + WINDOW *empty_stack = NULL; + + wbkgd(stack->card->frame->shape, WHITE_ON_GREEN); + wrefresh(stack->card->frame->shape); + empty_stack = newwin(FRAME_HEIGHT, + FRAME_WIDTH, + stack->card->frame->start_y, + stack->card->frame->start_x); + box(empty_stack, 0, 0); + wrefresh(empty_stack); + delwin(empty_stack); + + return; +} + void draw_empty_stacks() { WINDOW **empty_stack; diff --git a/lib/display.h b/lib/display.h index 1a73859..2267836 100644 --- a/lib/display.h +++ b/lib/display.h @@ -13,9 +13,11 @@ #define BLACK_ON_WHITE 1 #define RED_ON_WHITE 2 #define WHITE_ON_BLUE 3 +#define WHITE_ON_GREEN 4 char *card_suit(enum suit); char *card_value(enum value); +void erase_stack(struct stack *); void draw_empty_stacks(); void draw_value(struct card *); void draw_suit(struct card *); diff --git a/lib/game.c b/lib/game.c index 5f51722..2693b09 100644 --- a/lib/game.c +++ b/lib/game.c @@ -220,14 +220,3 @@ void end_game(struct deck *deck) { return; } - -void handle_stock_event() { - if (!empty(deck->stock)) { - move_card(&(deck->stock), &(deck->waste_pile)); - expose_card(deck->waste_pile->card); - draw_stack(deck->stock); - draw_stack(deck->waste_pile); - } - - return; -} diff --git a/lib/game.h b/lib/game.h index cbaf141..c2c26fb 100644 --- a/lib/game.h +++ b/lib/game.h @@ -36,6 +36,5 @@ void greet_player(); void initialize_game(); void prepare_game(struct deck **); void end_game(); -void handle_stock_event(); #endif diff --git a/lib/keyboard.c b/lib/keyboard.c index 5466c42..1ec156d 100644 --- a/lib/keyboard.c +++ b/lib/keyboard.c @@ -1,6 +1,22 @@ #include +#include "display.h" #include "keyboard.h" +void handle_stock_event() { + if (!empty(deck->stock)) { + /* erase the stack before emptying it */ + if (length(deck->stock) == 1) { + erase_stack(deck->stock); + } + move_card(&(deck->stock), &(deck->waste_pile)); + expose_card(deck->waste_pile->card); + draw_stack(deck->stock); + draw_stack(deck->waste_pile); + } + + return; +} + int key_event() { int pressed_key; diff --git a/lib/keyboard.h b/lib/keyboard.h index 72660e3..584da02 100644 --- a/lib/keyboard.h +++ b/lib/keyboard.h @@ -1,8 +1,13 @@ #ifndef KEYBOARD_H #define KEYBOARD_H +#include "deck.h" + #define KEY_SPACEBAR ' ' +extern struct deck *deck; + +void handle_stock_event(); int key_event(); #endif diff --git a/lib/stack.c b/lib/stack.c index 2dd5063..adeab97 100644 --- a/lib/stack.c +++ b/lib/stack.c @@ -1,6 +1,7 @@ #include #include #include "stack.h" +#include "game.h" void allocate_stack(struct stack **stack) { *stack = malloc(sizeof(**stack)); @@ -79,7 +80,12 @@ struct stack *pop(struct stack **stack) { } bool maneuvre_stack(struct stack *stack) { - return(stack->card->frame->start_y >= MANEUVRE_STACKS_START_Y); + return(stack->card->frame->start_y >= MANEUVRE_STACKS_STARTING_Y); +} + +bool waste_pile_stack(struct stack *stack) { + return((stack->card->frame->start_x == WASTE_PILE_STARTING_X) && + (stack->card->frame->start_y == WASTE_PILE_STARTING_Y)); } void refresh_card_coordinates(struct stack *origin, struct stack *destination) { diff --git a/lib/stack.h b/lib/stack.h index 3b52d05..9a4fa6c 100644 --- a/lib/stack.h +++ b/lib/stack.h @@ -3,7 +3,7 @@ #include "card.h" -#define MANEUVRE_STACKS_START_Y 7 +#define MANEUVRE_STACKS_STARTING_Y 7 struct stack { struct card *card; @@ -18,6 +18,7 @@ int length(struct stack *); void push(struct stack **, struct card *); struct stack *pop(struct stack **); bool maneuvre_stack(struct stack *); +bool waste_pile_stack(struct stack *); void refresh_card_coordinates(struct stack *, struct stack *); void move_card(struct stack **, struct stack **); diff --git a/lib/util.c b/lib/util.c index 64c732a..3f5ed7e 100644 --- a/lib/util.c +++ b/lib/util.c @@ -14,6 +14,7 @@ void initialize_curses() { init_pair(1, COLOR_BLACK, COLOR_WHITE); init_pair(2, COLOR_RED, COLOR_WHITE); init_pair(3, COLOR_WHITE, COLOR_BLUE); + init_pair(4, COLOR_WHITE, COLOR_GREEN); return; }