Skip to content

Add more keyboard keys #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,16 @@ void move_block(struct stack **origin, struct stack **destination,
if (stack_length(*destination) > 1) {
cursor->y += block_size;
}
stack_free(tmp);
}

void expose_top(struct stack **origin)
{
struct card *top;
if((top = stack_pop(origin)))
{
card_expose(top);
stack_push(origin, top);
}
}

static void fill_deck(struct deck *deck) {
Expand Down
1 change: 1 addition & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ bool stock_stack(struct stack *);
bool valid_move(struct stack *, struct stack *);
void move_card(struct stack **, struct stack **);
void move_block(struct stack **, struct stack **, int);
void expose_top(struct stack **);
void game_init(struct game *, int, int);
bool game_won();
void game_end();
Expand Down
77 changes: 76 additions & 1 deletion src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,43 @@ static void handle_card_movement(struct cursor *cursor) {
draw_stack(*origin);
}
break;

case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
erase_cursor(cursor);
int key_as_index = key - '1';
cursor->x = CURSOR_MANEUVRE_0_X + 8 * (key_as_index);
cursor->y = CURSOR_BEGIN_Y + 7 + stack_length(deck->maneuvre[key_as_index]);
draw_cursor(cursor);
break;
case 's':
case 'S':
erase_cursor(cursor);
cursor->x = CURSOR_STOCK_X;
cursor->y = CURSOR_BEGIN_Y;
draw_cursor(cursor);
break;
case 'w':
case 'W':
erase_cursor(cursor);
cursor->x = CURSOR_WASTE_PILE_X;
cursor->y = CURSOR_BEGIN_Y;
draw_cursor(cursor);
break;
case KEY_F1: // F1 key
case KEY_F2: // F2 key
case KEY_F3: // F3 key
case KEY_F4: // F4 key
erase_cursor(cursor);
int fkey_as_index = key - KEY_F1;
cursor->x = CURSOR_FOUNDATION_0_X + 8 * fkey_as_index;
cursor->y = CURSOR_BEGIN_Y;
draw_cursor(cursor);
break;
case KEY_SPACEBAR:;
/* http://www.mail-archive.com/[email protected]/msg259382.html */
struct stack **destination = cursor_stack(cursor);
Expand All @@ -157,13 +193,15 @@ static void handle_card_movement(struct cursor *cursor) {
;
if (valid_move(block, *destination)) {
move_block(origin, destination, _marked_cards_count);
expose_top(origin);
}
} else {
if (valid_move(*origin, *destination)) {
if (maneuvre_stack(*destination)) {
cursor->y++;
}
move_card(origin, destination);
expose_top(origin);
}
}
draw_stack(*origin);
Expand Down Expand Up @@ -226,6 +264,43 @@ void keyboard_event(int key) {
cursor_move(cursor, cursor_direction(key));
draw_cursor(cursor);
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
erase_cursor(cursor);
int key_as_index = key - '1';
cursor->x = CURSOR_MANEUVRE_0_X + 8 * (key_as_index);
cursor->y = CURSOR_BEGIN_Y + 7 + stack_length(deck->maneuvre[key_as_index]);
draw_cursor(cursor);
break;
case 's':
case 'S':
erase_cursor(cursor);
cursor->x = CURSOR_STOCK_X;
cursor->y = CURSOR_BEGIN_Y;
draw_cursor(cursor);
break;
case 'w':
case 'W':
erase_cursor(cursor);
cursor->x = CURSOR_WASTE_PILE_X;
cursor->y = CURSOR_BEGIN_Y;
draw_cursor(cursor);
break;
case KEY_F1: // F1 key
case KEY_F2: // F2 key
case KEY_F3: // F3 key
case KEY_F4: // F4 key
erase_cursor(cursor);
int fkey_as_index = key - KEY_F1;
cursor->x = CURSOR_FOUNDATION_0_X + 8 * fkey_as_index;
cursor->y = CURSOR_BEGIN_Y;
draw_cursor(cursor);
break;
case KEY_SPACEBAR:
if (cursor_on_stock(cursor)) {
if (stack_empty(deck->stock)) {
Expand Down
6 changes: 5 additions & 1 deletion src/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include "cursor.h"

#define KEY_SPACEBAR 32
#define KEY_ESCAPE 27
#define KEY_ESCAPE 277
#define KEY_F1 265
#define KEY_F2 266
#define KEY_F3 267
#define KEY_F4 268

extern struct deck *deck;
extern struct cursor *cursor;
Expand Down
11 changes: 7 additions & 4 deletions src/ttysolitaire.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ int main(int argc, char *argv[]) {
void draw_greeting() {
mvprintw(8, 26, "Welcome to tty-solitaire.");
mvprintw(10, 21, "Move with the arrow keys or <hjkl>.");
mvprintw(11, 18, "Use the space bar to select and place cards.");
mvprintw(12, 13, "After selecting a card you can use <m> to select more");
mvprintw(13, 13, "and <n> to select less. Press <Shift+M> to select all.");
mvprintw(15, 19, "Press the space bar to play or q to quit.");
mvprintw(11, 18, "Use <w> to move to the waste pile, <s> to move to");
mvprintw(12, 13, "the stock pile, <1...7> to move between the maneuvers,");
mvprintw(13, 13, "and <F1...F4> to move between the foundations.");
mvprintw(14, 18, "Use the space bar to select and place cards.");
mvprintw(15, 13, "After selecting a card you can use <m> to select more");
mvprintw(16, 13, "and <n> to select less. Press <Shift+M> to select all.");
mvprintw(18, 19, "Press the space bar to play or q to quit.");
}

void usage(const char *program_name) {
Expand Down