diff --git a/Makefile b/Makefile index f06f89d..340eb89 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ +VERSION = 1.0.0 + CC ?= gcc CFLAGS ?= -g -CFLAGS += -W -Wall -pedantic -ansi -std=c99 -g +CFLAGS += -W -Wall -pedantic -ansi -std=c99 -DTS_VERSION=\"$(VERSION)\" # OS X installs ncurses with wide character support, but not as "libncurses" ifeq ($(shell uname -s),Darwin) @@ -9,7 +11,7 @@ else LDFLAGS += -lncursesw endif -PREFIX ?= /usr/local +PREFIX ?= /usr/local EXECUTABLE = ttysolitaire SRC_DIR = src @@ -40,6 +42,8 @@ TESTS_OBJECTS = $(TESTS_DIR)/frame_test.o \ .PHONY: test clean install uninstall +all: ${EXECUTABLE} + ttysolitaire: $(SRC_OBJECTS) $(CC) $(CFLAGS) $(SRC) -o $(EXECUTABLE) $(SRC_OBJECTS) $(LDFLAGS) diff --git a/VERSION b/VERSION deleted file mode 100644 index 3eefcb9..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.0.0 diff --git a/src/game.c b/src/game.c index c22e3ec..485a39c 100644 --- a/src/game.c +++ b/src/game.c @@ -129,7 +129,6 @@ void move_block(struct stack **origin, struct stack **destination, int block_siz stack_free(tmp); } - static void fill_deck(struct deck *deck) { struct card *card[NUMBER_OF_CARDS]; @@ -166,10 +165,10 @@ static void shuffle_deck(struct deck *deck) { } static void deal_cards(struct deck *deck) { - for (int i = 0; i < 7; i++) { + for (int i = 0; i < MANEUVRE_STACKS_NUMBER; i++) { move_card(&(deck->stock), &(deck->maneuvre[i])); card_expose(deck->maneuvre[i]->card); - for (int j = i + 1; j < 7; j++) { + for (int j = i + 1; j < MANEUVRE_STACKS_NUMBER; j++) { move_card(&(deck->stock), &(deck->maneuvre[j])); } } @@ -207,8 +206,14 @@ void game_end() { } bool game_won() { - return(stack_length(deck->foundation[0]) == 13 && - stack_length(deck->foundation[1]) == 13 && - stack_length(deck->foundation[2]) == 13 && - stack_length(deck->foundation[3]) == 13); + // if any card is covered, game is not won + for (int i = 0; i < MANEUVRE_STACKS_NUMBER; i++) + for (struct stack *j = deck->maneuvre[i]; j!= NULL; j = j->next) + if (j->card->face == COVERED) + return false; + // else look in stock and waste pile + if (stack_empty(deck->stock) && + stack_empty(deck->waste_pile)) + return true; + else return false; } diff --git a/src/keyboard.c b/src/keyboard.c index f5928d2..07a1b05 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -95,6 +95,18 @@ static void handle_card_movement(struct cursor *cursor) { } } break; + case 'M': + if (origin == cursor_stack(cursor) && maneuvre_stack(*origin)) { + for (struct stack *i = *origin; i && i->next; i = i->next) { + if (i->next->card->face == EXPOSED && + (i->card->frame->begin_y - i->next->card->frame->begin_y) > 1) { + erase_stack(*origin); + card_mark(i->next->card); + draw_stack(*origin); + } + } + } + break; case 'n': if (origin == cursor_stack(cursor) && maneuvre_stack(*origin)) { for (struct stack *i = (*origin)->next; i; i = i->next) { @@ -116,6 +128,15 @@ static void handle_card_movement(struct cursor *cursor) { } } break; + case 'N': + if (origin == cursor_stack(cursor) && maneuvre_stack(*origin)) { + erase_stack(*origin); + unmark_cards(*origin); + card_mark((*origin)->card); + draw_stack(*origin); + } + break; + case KEY_SPACEBAR:; /* http://www.mail-archive.com/gcc-bugs@gcc.gnu.org/msg259382.html */ struct stack **destination = cursor_stack(cursor); diff --git a/src/ttysolitaire.c b/src/ttysolitaire.c index 1861f3f..cbc5442 100644 --- a/src/ttysolitaire.c +++ b/src/ttysolitaire.c @@ -8,6 +8,10 @@ #include "keyboard.h" #include "common.h" +#ifndef TS_VERSION +#define TS_VERSION "n/a" +#endif + const char *program_name; struct game game; @@ -123,14 +127,5 @@ void usage(const char *program_name) { } void version() { - FILE *version_file; - char version_string[6]; - - if (!(version_file = fopen("VERSION", "rb"))) { - tty_solitaire_generic_error(errno, __FILE__, __LINE__); - } - fread(version_string, 1, 5, version_file); - version_string[5] = '\0'; - printf("%s\n", version_string); - fclose(version_file); + printf("%s\n", TS_VERSION); } diff --git a/tests/game_test.c b/tests/game_test.c index ed6833f..9b30d14 100644 --- a/tests/game_test.c +++ b/tests/game_test.c @@ -129,6 +129,7 @@ void test_valid_move_from_waste_pile_to_foundation_stacks() { card_set(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X); card_set(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X); for (int i = 0; i < 4; i++) { + // TODO: fix error here assert(valid_move(waste_pile, foundation_stacks[i])); } stack_free(waste_pile); @@ -155,6 +156,7 @@ void test_valid_move_from_waste_pile_to_maneuvre_stacks() { card_set(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X); card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X); for (int i = 0; i < 7; i++) { + // TODO: fix error here assert(valid_move(waste_pile, maneuvre_stacks[i])); } stack_free(waste_pile); @@ -225,6 +227,7 @@ void test_valid_move_from_foundation_stack_to_foundation_stacks() { if (i == j) { assert(!valid_move(foundation_stacks[i], foundation_stacks[j])); } else { + // TODO: fix error here assert(valid_move(foundation_stacks[i], foundation_stacks[j])); } } @@ -259,6 +262,7 @@ void test_valid_move_from_foundation_stack_to_maneuvre_stacks() { card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X); for (int i = 0; i < 4; i++) { for (int j = 0; j < 7; j++) { + // TODO: fix error here assert(valid_move(foundation_stacks[i], maneuvre_stacks[j])); } } @@ -347,6 +351,7 @@ void test_valid_move_from_maneuvre_stack_to_foundation_stacks() { card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X); for (int i = 0; i < 7; i++) { for (int j = 0; j < 4; j++) { + // TODO: fix error here assert(valid_move(maneuvre_stacks[i], foundation_stacks[j])); } } @@ -377,6 +382,7 @@ void test_valid_move_from_maneuvre_stack_to_maneuvre_stacks() { if (i == j) { assert(!valid_move(maneuvre_stacks[i], maneuvre_stacks[j])); } else { + // TODO: fix error here assert(valid_move(maneuvre_stacks[i], maneuvre_stacks[j])); } } diff --git a/tests/stack_test.c b/tests/stack_test.c index e23a042..9776af3 100644 --- a/tests/stack_test.c +++ b/tests/stack_test.c @@ -217,7 +217,7 @@ void test_stack_reverse_on_stack_empty_stack() { old_stack = stack; stack_reversed_stack = stack_reverse(stack); - assert(stack_reversed_stack == old_stack); + assert(stacks_equal(stack_reversed_stack, old_stack)); stack_free(stack); } @@ -236,7 +236,7 @@ void test_stack_reverse_on_stack_with_one_element() { old_stack = stack; stack_reversed_stack = stack_reverse(stack); - assert(stack_reversed_stack == old_stack); + assert(stacks_equal(stack_reversed_stack, old_stack)); stack_free(stack); }