Added option to control the number of passes through the deck.
This commit is contained in:
parent
a213bfec55
commit
7aaa0c82cb
@ -34,6 +34,7 @@ struct cursor {
|
|||||||
enum movement { LEFT, DOWN, UP, RIGHT };
|
enum movement { LEFT, DOWN, UP, RIGHT };
|
||||||
|
|
||||||
extern struct deck *deck;
|
extern struct deck *deck;
|
||||||
|
extern struct game game;
|
||||||
|
|
||||||
void cursor_malloc(struct cursor **);
|
void cursor_malloc(struct cursor **);
|
||||||
void cursor_init(struct cursor *);
|
void cursor_init(struct cursor *);
|
||||||
|
@ -64,6 +64,13 @@ void draw_card(struct card *card) {
|
|||||||
void draw_stack(struct stack *stack) {
|
void draw_stack(struct stack *stack) {
|
||||||
if (stack_empty(stack)) {
|
if (stack_empty(stack)) {
|
||||||
box(stack->card->frame->window, 0, 0);
|
box(stack->card->frame->window, 0, 0);
|
||||||
|
if (stock_stack(stack)) {
|
||||||
|
if (game.passes_through_deck_left >= 1) {
|
||||||
|
mvwprintw(stack->card->frame->window, 2, 3, "O");
|
||||||
|
} else {
|
||||||
|
mvwprintw(stack->card->frame->window, 2, 3, "X");
|
||||||
|
}
|
||||||
|
}
|
||||||
wrefresh(stack->card->frame->window);
|
wrefresh(stack->card->frame->window);
|
||||||
} else {
|
} else {
|
||||||
if (maneuvre_stack(stack)) {
|
if (maneuvre_stack(stack)) {
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#define WHITE_ON_BLUE 3
|
#define WHITE_ON_BLUE 3
|
||||||
#define WHITE_ON_GREEN 4
|
#define WHITE_ON_GREEN 4
|
||||||
|
|
||||||
|
extern struct game game;
|
||||||
|
|
||||||
void draw_card(struct card *);
|
void draw_card(struct card *);
|
||||||
void draw_stack(struct stack *);
|
void draw_stack(struct stack *);
|
||||||
void draw_deck(struct deck *);
|
void draw_deck(struct deck *);
|
||||||
|
14
src/game.c
14
src/game.c
@ -43,11 +43,6 @@ static int maneuvre_begin_x(int x) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool stock_stack(struct stack *stack) {
|
|
||||||
return((stack->card->frame->begin_y == STOCK_BEGIN_Y) &&
|
|
||||||
(stack->card->frame->begin_x == STOCK_BEGIN_X));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool waste_pile_stack(struct stack *stack) {
|
static bool waste_pile_stack(struct stack *stack) {
|
||||||
return((stack->card->frame->begin_y == WASTE_PILE_BEGIN_Y) &&
|
return((stack->card->frame->begin_y == WASTE_PILE_BEGIN_Y) &&
|
||||||
(stack->card->frame->begin_x == WASTE_PILE_BEGIN_X));
|
(stack->card->frame->begin_x == WASTE_PILE_BEGIN_X));
|
||||||
@ -61,6 +56,11 @@ static bool foundation_stack(struct stack *stack) {
|
|||||||
stack->card->frame->begin_x == FOUNDATION_3_BEGIN_X));
|
stack->card->frame->begin_x == FOUNDATION_3_BEGIN_X));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool stock_stack(struct stack *stack) {
|
||||||
|
return((stack->card->frame->begin_y == STOCK_BEGIN_Y) &&
|
||||||
|
(stack->card->frame->begin_x == STOCK_BEGIN_X));
|
||||||
|
}
|
||||||
|
|
||||||
bool maneuvre_stack(struct stack *stack) {
|
bool maneuvre_stack(struct stack *stack) {
|
||||||
return(stack->card->frame->begin_y >= MANEUVRE_BEGIN_Y &&
|
return(stack->card->frame->begin_y >= MANEUVRE_BEGIN_Y &&
|
||||||
(stack->card->frame->begin_x == MANEUVRE_0_BEGIN_X ||
|
(stack->card->frame->begin_x == MANEUVRE_0_BEGIN_X ||
|
||||||
@ -177,7 +177,7 @@ static void deal_cards(struct deck *deck) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_init() {
|
void game_init(struct game *game, int passes_through_deck) {
|
||||||
cursor_malloc(&cursor);
|
cursor_malloc(&cursor);
|
||||||
cursor_init(cursor);
|
cursor_init(cursor);
|
||||||
deck_malloc(&deck);
|
deck_malloc(&deck);
|
||||||
@ -199,6 +199,8 @@ void game_init() {
|
|||||||
|
|
||||||
draw_cursor(cursor);
|
draw_cursor(cursor);
|
||||||
draw_deck(deck);
|
draw_deck(deck);
|
||||||
|
|
||||||
|
game->passes_through_deck_left = passes_through_deck;
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_end() {
|
void game_end() {
|
||||||
|
@ -30,14 +30,19 @@
|
|||||||
#define MANEUVRE_5_BEGIN_X 41
|
#define MANEUVRE_5_BEGIN_X 41
|
||||||
#define MANEUVRE_6_BEGIN_X 49
|
#define MANEUVRE_6_BEGIN_X 49
|
||||||
|
|
||||||
|
struct game {
|
||||||
|
int passes_through_deck_left;
|
||||||
|
};
|
||||||
|
|
||||||
struct deck *deck;
|
struct deck *deck;
|
||||||
struct cursor *cursor;
|
struct cursor *cursor;
|
||||||
|
|
||||||
bool maneuvre_stack(struct stack *);
|
bool maneuvre_stack(struct stack *);
|
||||||
|
bool stock_stack(struct stack *);
|
||||||
bool valid_move(struct stack *, struct stack *);
|
bool valid_move(struct stack *, struct stack *);
|
||||||
void move_card(struct stack **, struct stack **);
|
void move_card(struct stack **, struct stack **);
|
||||||
void move_block(struct stack **, struct stack **, int);
|
void move_block(struct stack **, struct stack **, int);
|
||||||
void game_init();
|
void game_init(struct game *, int);
|
||||||
bool game_won();
|
bool game_won();
|
||||||
void game_end();
|
void game_end();
|
||||||
|
|
||||||
|
@ -178,10 +178,20 @@ void keyboard_event(int key) {
|
|||||||
break;
|
break;
|
||||||
case KEY_SPACEBAR:
|
case KEY_SPACEBAR:
|
||||||
if (cursor_on_stock(cursor)) {
|
if (cursor_on_stock(cursor)) {
|
||||||
if (!stack_empty(deck->stock)) {
|
if (stack_empty(deck->stock)) {
|
||||||
|
if (game.passes_through_deck_left >= 1) {
|
||||||
|
while (!stack_empty(deck->waste_pile)) {
|
||||||
|
move_card(&(deck->waste_pile), &(deck->stock));
|
||||||
|
}
|
||||||
|
draw_stack(deck->stock);
|
||||||
|
draw_stack(deck->waste_pile);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
move_card(&(deck->stock), &(deck->waste_pile));
|
move_card(&(deck->stock), &(deck->waste_pile));
|
||||||
|
if (stack_empty(deck->stock)) {
|
||||||
|
game.passes_through_deck_left--;
|
||||||
|
}
|
||||||
card_expose(deck->waste_pile->card);
|
card_expose(deck->waste_pile->card);
|
||||||
erase_stack(deck->waste_pile);
|
|
||||||
draw_stack(deck->stock);
|
draw_stack(deck->stock);
|
||||||
draw_stack(deck->waste_pile);
|
draw_stack(deck->waste_pile);
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
extern struct deck *deck;
|
extern struct deck *deck;
|
||||||
extern struct cursor *cursor;
|
extern struct cursor *cursor;
|
||||||
|
extern struct game game;
|
||||||
|
|
||||||
void keyboard_event();
|
void keyboard_event();
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
|
|
||||||
const char *program_name;
|
const char *program_name;
|
||||||
|
struct game game;
|
||||||
|
|
||||||
void draw_greeting() {
|
void draw_greeting() {
|
||||||
mvprintw(8, 26, "Welcome to tty-solitaire.");
|
mvprintw(8, 26, "Welcome to tty-solitaire.");
|
||||||
@ -36,18 +37,23 @@ void version() {
|
|||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int option;
|
int option;
|
||||||
int option_index;
|
int option_index;
|
||||||
|
int passes_through_deck = 3;
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"version", no_argument, NULL, 'v'}
|
{"version", no_argument, NULL, 'v'},
|
||||||
|
{"passes", required_argument, NULL, 'p'}
|
||||||
};
|
};
|
||||||
|
|
||||||
program_name = argv[0];
|
program_name = argv[0];
|
||||||
|
|
||||||
while ((option = getopt_long(argc, argv, "hv", options, &option_index)) != -1) {
|
while ((option = getopt_long(argc, argv, "hvp:", options, &option_index)) != -1) {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 'v':
|
case 'v':
|
||||||
version();
|
version();
|
||||||
exit(0);
|
exit(0);
|
||||||
|
case 'p':
|
||||||
|
passes_through_deck = atoi(optarg);
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
@ -77,7 +83,7 @@ int main(int argc, char *argv[]) {
|
|||||||
case KEY_SPACEBAR:
|
case KEY_SPACEBAR:
|
||||||
clear();
|
clear();
|
||||||
refresh();
|
refresh();
|
||||||
game_init();
|
game_init(&game, passes_through_deck);
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
case 'Q':
|
case 'Q':
|
||||||
|
Loading…
Reference in New Issue
Block a user