Passing cards from the stock to the waste pile.

This commit is contained in:
Murilo Soares Pereira 2010-04-20 14:11:16 -03:00
parent ee3daeb30a
commit 87909b5075
6 changed files with 27 additions and 0 deletions

View File

@ -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));
}

View File

@ -1,6 +1,8 @@
#ifndef CURSOR_H
#define CURSOR_H
#include <stdbool.h>
#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

View File

@ -1,3 +1,4 @@
#include <stdlib.h>
#include <ncurses.h>
#include <malloc.h>
#include <string.h>

View File

@ -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;
}

View File

@ -36,5 +36,6 @@ void greet_player();
void initialize_game();
void prepare_game(struct deck **);
void end_game();
void handle_stock_event();
#endif

View File

@ -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();