diff --git a/src/draw.c b/src/draw.c index 73cfa37..f8015bb 100644 --- a/src/draw.c +++ b/src/draw.c @@ -12,15 +12,6 @@ static const char *card_values[13] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" }; -void draw_greeting() { - mvprintw(8, 26, "Welcome to tty-solitaire."); - mvprintw(10, 27, "Move with \u2190\u2191\u2192\u2193 or hjkl."); - mvprintw(11, 19, "Use the space bar to mark and move cards."); - mvprintw(12, 16, "After marking a card you can use m to increase "); - mvprintw(13, 17, "and n to decrease the number of marked cards."); - mvprintw(15, 19, "Press the space bar to play or q to quit."); -} - static void draw_value(struct card *card) { mvwprintw(card->frame->window, 0, 0, card_values[card->value]); mvwprintw(card->frame->window, diff --git a/src/draw.h b/src/draw.h index 8030735..9b83484 100644 --- a/src/draw.h +++ b/src/draw.h @@ -11,7 +11,6 @@ #define WHITE_ON_BLUE 3 #define WHITE_ON_GREEN 4 -void draw_greeting(); void draw_card(struct card *); void draw_stack(struct stack *); void draw_deck(struct deck *); diff --git a/src/game.c b/src/game.c index 5bf1086..6adad07 100644 --- a/src/game.c +++ b/src/game.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -204,3 +205,10 @@ void game_end() { free_cursor(cursor); free_deck(deck); } + +bool game_won() { + return(length(deck->foundation[0]) == 13 && + length(deck->foundation[1]) == 13 && + length(deck->foundation[2]) == 13 && + length(deck->foundation[3]) == 13); +} diff --git a/src/game.h b/src/game.h index 4a0f254..c3da680 100644 --- a/src/game.h +++ b/src/game.h @@ -1,6 +1,8 @@ #ifndef GAME_H #define GAME_H +#include + #include "stack.h" #include "deck.h" #include "cursor.h" @@ -36,6 +38,7 @@ bool valid_move(struct stack *, struct stack *); void move_card(struct stack **, struct stack **); void move_block(struct stack **, struct stack **, int); void game_init(); +bool game_won(); void game_end(); #endif diff --git a/src/ttysolitaire.c b/src/ttysolitaire.c index de28df8..28b227e 100644 --- a/src/ttysolitaire.c +++ b/src/ttysolitaire.c @@ -1,3 +1,4 @@ +#include #include #include @@ -7,6 +8,15 @@ const char *program_name; +void draw_greeting() { + mvprintw(8, 26, "Welcome to tty-solitaire."); + mvprintw(10, 27, "Move with \u2190\u2191\u2192\u2193 or hjkl."); + mvprintw(11, 19, "Use the space bar to mark and move cards."); + mvprintw(12, 16, "After marking a card you can use m to increase "); + mvprintw(13, 17, "and n to decrease the number of marked cards."); + mvprintw(15, 19, "Press the space bar to play or q to quit."); +} + int main(int argc, const char *argv[]) { program_name = *argv; @@ -45,10 +55,15 @@ int main(int argc, const char *argv[]) { if ((key = getch()) == 'q' || key == 'Q') { endwin(); game_end(); + exit(0); } else { handle_keyboard_event(key); } - } while (key != 'q' && key != 'Q'); + } while (!game_won()); + + endwin(); + game_end(); + printf("You won.\n"); return(0); }