Moving responsibility off from main file.

This commit is contained in:
Murilo Pereira
2011-02-06 00:32:21 -02:00
parent 8bd7147a8e
commit 196a11d1fe
4 changed files with 42 additions and 35 deletions

View File

@@ -217,6 +217,7 @@ void initialize_game() {
}
void end_game(struct deck *deck) {
print_deck(deck); // debugging purposes
delete_deck(deck);
return;

View File

@@ -111,3 +111,33 @@ int key_event() {
return(pressed_key);
}
void handle_keyboard_event(int key) {
switch (key) {
case 'h':
case KEY_LEFT:
move_cursor(cursor, LEFT);
break;
case 'j':
case KEY_DOWN:
move_cursor(cursor, DOWN);
break;
case 'k':
case KEY_UP:
move_cursor(cursor, UP);
break;
case 'l':
case KEY_RIGHT:
move_cursor(cursor, RIGHT);
break;
case KEY_SPACEBAR:
if (cursor_on_stock(cursor)) {
handle_stock_event();
} else {
handle_card_movement(cursor);
}
break;
}
return;
}

View File

@@ -7,6 +7,7 @@
#define KEY_SPACEBAR ' '
extern struct deck *deck;
extern struct cursor *cursor;
void mark_origin(struct cursor *);
struct stack *cursor_stack(struct cursor *);
@@ -15,5 +16,6 @@ bool cursor_on_invalid_spot(struct cursor *);
void handle_stock_event();
void handle_card_movement(struct cursor *);
int key_event();
void handle_keyboard_event();
#endif