Added game_won().

This commit is contained in:
Murilo Pereira 2011-06-06 00:42:23 -03:00
parent 4d3892101d
commit 2d27a53d95
5 changed files with 27 additions and 11 deletions

View File

@ -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,

View File

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

View File

@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <malloc.h>
#include <errno.h>
#include <time.h>
@ -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);
}

View File

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

View File

@ -1,3 +1,4 @@
#include <stdlib.h>
#include <ncurses.h>
#include <locale.h>
@ -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);
}