Moving responsibility off from main file.
This commit is contained in:
@@ -217,6 +217,7 @@ void initialize_game() {
|
||||
}
|
||||
|
||||
void end_game(struct deck *deck) {
|
||||
print_deck(deck); // debugging purposes
|
||||
delete_deck(deck);
|
||||
|
||||
return;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user