From 87909b507580567b43d029a321b3ab581cc70720 Mon Sep 17 00:00:00 2001 From: Murilo Soares Pereira Date: Tue, 20 Apr 2010 14:11:16 -0300 Subject: [PATCH] Passing cards from the stock to the waste pile. --- lib/cursor.c | 4 ++++ lib/cursor.h | 3 +++ lib/display.c | 1 + lib/game.c | 11 +++++++++++ lib/game.h | 1 + src/tty-solitaire.c | 7 +++++++ 6 files changed, 27 insertions(+) diff --git a/lib/cursor.c b/lib/cursor.c index a9c07db..3469fe9 100644 --- a/lib/cursor.c +++ b/lib/cursor.c @@ -100,3 +100,7 @@ void move_cursor(struct cursor *cursor, enum movement movement) { return; } + +bool cursor_on_stock(struct cursor *cursor) { + return((cursor->x == CURSOR_STARTING_X) && (cursor->y == CURSOR_STARTING_Y)); +} diff --git a/lib/cursor.h b/lib/cursor.h index 80d08b4..93510c5 100644 --- a/lib/cursor.h +++ b/lib/cursor.h @@ -1,6 +1,8 @@ #ifndef CURSOR_H #define CURSOR_H +#include + #define CURSOR_STARTING_X 4 #define CURSOR_STARTING_Y 7 @@ -17,5 +19,6 @@ void allocate_cursor(struct cursor **); void initialize_cursor(struct cursor *); void draw_cursor(struct cursor *); void move_cursor(struct cursor *, enum movement); +bool cursor_on_stock(struct cursor *); #endif diff --git a/lib/display.c b/lib/display.c index 9befe79..8080385 100644 --- a/lib/display.c +++ b/lib/display.c @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/lib/game.c b/lib/game.c index 2693b09..5f51722 100644 --- a/lib/game.c +++ b/lib/game.c @@ -220,3 +220,14 @@ 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 c2c26fb..cbaf141 100644 --- a/lib/game.h +++ b/lib/game.h @@ -36,5 +36,6 @@ void greet_player(); void initialize_game(); void prepare_game(struct deck **); void end_game(); +void handle_stock_event(); #endif diff --git a/src/tty-solitaire.c b/src/tty-solitaire.c index dc92450..f9f185b 100644 --- a/src/tty-solitaire.c +++ b/src/tty-solitaire.c @@ -46,6 +46,13 @@ int main(int argc, const char *argv[]) { case KEY_RIGHT: move_cursor(cursor, RIGHT); break; + case KEY_SPACEBAR: + if (cursor_on_stock(cursor)) { + handle_stock_event(); + } else { + /*handle_card_event();*/ + } + break; case 'q': case 'Q': end_curses();