Add four color mode

Fix #32
This commit is contained in:
Sebastian Riedel 2019-01-14 06:52:38 +01:00
parent 57c481f506
commit 90e50dcc4c
6 changed files with 47 additions and 14 deletions

3
README
View File

@ -44,10 +44,11 @@
** Usage
#+BEGIN_SRC text
usage: ttysolitaire [-v|--version] [-h|--help] [-p|--passes=NUMBER]
usage: ttysolitaire [-v|--version] [-h|--help] [-p|--passes=NUMBER] [-c|--colors]
-v, --version Show version
-h, --help Show this message
-p, --passes Number of passes through the deck
-c, --colors Four unique colors, one for each suit
#+END_SRC
** Development

View File

@ -174,7 +174,7 @@ static void deal_cards(struct deck *deck) {
}
}
void game_init(struct game *game, int passes_through_deck) {
void game_init(struct game *game, int passes_through_deck, int color_mode) {
cursor_malloc(&cursor);
cursor_init(cursor);
deck_malloc(&deck);
@ -190,6 +190,8 @@ void game_init(struct game *game, int passes_through_deck) {
frame_set(deck->maneuvre[i]->card->frame, MANEUVRE_BEGIN_Y, maneuvre_begin_x(i));
}
game->color_mode = color_mode;
fill_deck(deck);
shuffle_deck(deck);
deal_cards(deck);

View File

@ -32,6 +32,7 @@
struct game {
int passes_through_deck_left;
int color_mode;
};
struct deck *deck;
@ -42,7 +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 game_init(struct game *, int);
void game_init(struct game *, int, int);
bool game_won();
void game_end();

View File

@ -6,6 +6,7 @@
#include "gui.h"
#include "deck.h"
#include "game.h"
#include "card.h"
static const char *card_suits[4] = { "\u2666", "\u2660", "\u2665", "\u2663" };
static const char *card_values[13] = {
@ -21,10 +22,28 @@ static void draw_value(struct card *card) {
}
static void draw_suit(struct card *card) {
if (card->suit % 2 == 0) {
wattron(card->frame->window, COLOR_PAIR(RED_ON_WHITE));
if (game.color_mode == 0) {
if (card->suit % 2 == 0) {
wattron(card->frame->window, COLOR_PAIR(RED_ON_WHITE));
} else {
wattron(card->frame->window, COLOR_PAIR(BLACK_ON_WHITE));
}
} else {
wattron(card->frame->window, COLOR_PAIR(BLACK_ON_WHITE));
switch (card->suit) {
case SPADES:
wattron(card->frame->window, COLOR_PAIR(GREEN_ON_WHITE));
break;
case DIAMONDS:
wattron(card->frame->window, COLOR_PAIR(YELLOW_ON_WHITE));
break;
case CLUBS:
wattron(card->frame->window, COLOR_PAIR(BLACK_ON_WHITE));
break;
case HEARTS:
default:
wattron(card->frame->window, COLOR_PAIR(RED_ON_WHITE));
break;
}
}
mvwprintw(card->frame->window,
0,

View File

@ -6,10 +6,12 @@
#include "deck.h"
#include "cursor.h"
#define BLACK_ON_WHITE 1
#define RED_ON_WHITE 2
#define WHITE_ON_BLUE 3
#define WHITE_ON_GREEN 4
#define BLACK_ON_WHITE 1
#define RED_ON_WHITE 2
#define GREEN_ON_WHITE 3
#define YELLOW_ON_WHITE 4
#define WHITE_ON_BLUE 5
#define WHITE_ON_GREEN 6
extern struct game game;

View File

@ -23,9 +23,11 @@ int main(int argc, char *argv[]) {
int option;
int option_index;
int passes_through_deck = 3;
int color_mode = 0;
static const struct option options[] = {
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{"colors", no_argument, NULL, 'c'},
{"passes", required_argument, NULL, 'p'},
{0, 0, 0, 0}
};
@ -40,6 +42,9 @@ int main(int argc, char *argv[]) {
case 'p':
passes_through_deck = atoi(optarg);
break;
case 'c':
color_mode = 1;
break;
case 'h':
default:
usage(program_name);
@ -58,8 +63,10 @@ int main(int argc, char *argv[]) {
assume_default_colors(COLOR_WHITE, COLOR_GREEN);
init_pair(1, COLOR_BLACK, COLOR_WHITE);
init_pair(2, COLOR_RED, COLOR_WHITE);
init_pair(3, COLOR_WHITE, COLOR_BLUE);
init_pair(4, COLOR_WHITE, COLOR_GREEN);
init_pair(3, COLOR_GREEN, COLOR_WHITE);
init_pair(4, COLOR_YELLOW, COLOR_WHITE);
init_pair(5, COLOR_WHITE, COLOR_BLUE);
init_pair(6, COLOR_WHITE, COLOR_GREEN);
int key;
@ -89,7 +96,7 @@ int main(int argc, char *argv[]) {
if (key == KEY_SPACEBAR) {
clear();
refresh();
game_init(&game, passes_through_deck);
game_init(&game, passes_through_deck, color_mode);
break;
}
} else if (key == KEY_RESIZE) {
@ -120,10 +127,11 @@ void draw_greeting() {
}
void usage(const char *program_name) {
printf("usage: %s [-v|--version] [-h|--help] [-p|--passes=NUMBER]\n", program_name);
printf("usage: %s [-v|--version] [-h|--help] [-p|--passes=NUMBER] [-c|--colors]\n", program_name);
printf(" -v, --version Show version\n");
printf(" -h, --help Show this message\n");
printf(" -p, --passes Number of passes through the deck\n");
printf(" -c, --colors Four unique colors, one for each suit\n");
}
void version() {