Only one reference to symbol strings.
This commit is contained in:
parent
51c3b51a8b
commit
9fbd1cbcaf
42
src/card.h
42
src/card.h
@ -5,34 +5,22 @@
|
|||||||
|
|
||||||
enum value {
|
enum value {
|
||||||
NO_VALUE = -1,
|
NO_VALUE = -1,
|
||||||
ACE = 1,
|
ACE,
|
||||||
TWO = 2,
|
TWO,
|
||||||
THREE = 3,
|
THREE,
|
||||||
FOUR = 4,
|
FOUR,
|
||||||
FIVE = 5,
|
FIVE,
|
||||||
SIX = 6,
|
SIX,
|
||||||
SEVEN = 7,
|
SEVEN,
|
||||||
EIGHT = 8,
|
EIGHT,
|
||||||
NINE = 9,
|
NINE,
|
||||||
TEN = 10,
|
TEN,
|
||||||
JACK = 11,
|
JACK,
|
||||||
QUEEN = 12,
|
QUEEN,
|
||||||
KING = 13
|
KING
|
||||||
};
|
|
||||||
|
|
||||||
enum suit {
|
|
||||||
NO_SUIT = -1,
|
|
||||||
DIAMONDS = 0,
|
|
||||||
SPADES = 1,
|
|
||||||
HEARTS = 2,
|
|
||||||
CLUBS = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
enum face {
|
|
||||||
NO_FACE = -1,
|
|
||||||
COVERED = 0,
|
|
||||||
EXPOSED = 1
|
|
||||||
};
|
};
|
||||||
|
enum suit { NO_SUIT = -1, DIAMONDS, SPADES, HEARTS, CLUBS };
|
||||||
|
enum face { NO_FACE = -1, COVERED, EXPOSED };
|
||||||
|
|
||||||
struct card {
|
struct card {
|
||||||
struct frame *frame;
|
struct frame *frame;
|
||||||
|
@ -4,56 +4,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
static char *card_suit(enum suit suit) {
|
static const char *card_suits[4] = { "\u2666", "\u2660", "\u2665", "\u2663" };
|
||||||
char *card_suit;
|
static const char *card_values[13] = {
|
||||||
|
"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
|
||||||
if (!(card_suit = malloc(4 * sizeof(*card_suit)))) {
|
};
|
||||||
fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
|
|
||||||
exit(errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(suit) {
|
|
||||||
case DIAMONDS: strcpy(card_suit, DIAMONDS_SYMBOL); break;
|
|
||||||
case SPADES: strcpy(card_suit, SPADES_SYMBOL); break;
|
|
||||||
case HEARTS: strcpy(card_suit, HEARTS_SYMBOL); break;
|
|
||||||
case CLUBS: strcpy(card_suit, CLUBS_SYMBOL); break;
|
|
||||||
default: strcpy(card_suit, "?");
|
|
||||||
}
|
|
||||||
|
|
||||||
return(card_suit);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *card_value(enum value value) {
|
|
||||||
char *card_value;
|
|
||||||
|
|
||||||
if (!(card_value = malloc(2 * sizeof(*card_value)))) {
|
|
||||||
fprintf(stderr, tty_solitaire_error_message(errno, __FILE__, __LINE__));
|
|
||||||
exit(errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(value) {
|
|
||||||
case TWO: card_value = "2"; break;
|
|
||||||
case THREE: card_value = "3"; break;
|
|
||||||
case FOUR: card_value = "4"; break;
|
|
||||||
case FIVE: card_value = "5"; break;
|
|
||||||
case SIX: card_value = "6"; break;
|
|
||||||
case SEVEN: card_value = "7"; break;
|
|
||||||
case EIGHT: card_value = "8"; break;
|
|
||||||
case NINE: card_value = "9"; break;
|
|
||||||
case TEN: card_value = "10"; break;
|
|
||||||
case JACK: card_value = "J"; break;
|
|
||||||
case QUEEN: card_value = "Q"; break;
|
|
||||||
case KING: card_value = "K"; break;
|
|
||||||
case ACE: card_value = "A"; break;
|
|
||||||
default: card_value = "?";
|
|
||||||
}
|
|
||||||
|
|
||||||
return(card_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void erase_card(struct card *card) {
|
void erase_card(struct card *card) {
|
||||||
werase(card->frame->window);
|
werase(card->frame->window);
|
||||||
@ -72,11 +31,11 @@ void erase_stack(struct stack *stack) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void draw_value(struct card *card) {
|
void draw_value(struct card *card) {
|
||||||
mvwprintw(card->frame->window, 0, 0, card_value(card->value));
|
mvwprintw(card->frame->window, 0, 0, card_values[card->value]);
|
||||||
mvwprintw(card->frame->window,
|
mvwprintw(card->frame->window,
|
||||||
4,
|
4,
|
||||||
6 - (strlen(card_value(card->value)) - 1),
|
7 - strlen(card_values[card->value]),
|
||||||
card_value(card->value));
|
card_values[card->value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_suit(struct card *card) {
|
void draw_suit(struct card *card) {
|
||||||
@ -85,10 +44,14 @@ void draw_suit(struct card *card) {
|
|||||||
} else {
|
} else {
|
||||||
wattron(card->frame->window, COLOR_PAIR(BLACK_ON_WHITE));
|
wattron(card->frame->window, COLOR_PAIR(BLACK_ON_WHITE));
|
||||||
}
|
}
|
||||||
mvwprintw(card->frame->window, 0, 1 + (strlen(card_value(card->value) + 1)),
|
mvwprintw(card->frame->window,
|
||||||
card_suit(card->suit));
|
0,
|
||||||
mvwprintw(card->frame->window, 4, 5 - (strlen(card_value(card->value) + 1)),
|
strlen(card_values[card->value]),
|
||||||
card_suit(card->suit));
|
card_suits[card->suit]);
|
||||||
|
mvwprintw(card->frame->window,
|
||||||
|
4,
|
||||||
|
6 - strlen(card_values[card->value]),
|
||||||
|
card_suits[card->suit]);
|
||||||
if (card->suit % 2 == 0) {
|
if (card->suit % 2 == 0) {
|
||||||
wattroff(card->frame->window, COLOR_PAIR(RED_ON_WHITE));
|
wattroff(card->frame->window, COLOR_PAIR(RED_ON_WHITE));
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,11 +8,6 @@
|
|||||||
|
|
||||||
#define EMPTY_STACKS_NUMBER 13
|
#define EMPTY_STACKS_NUMBER 13
|
||||||
|
|
||||||
#define DIAMONDS_SYMBOL "\u2666"
|
|
||||||
#define SPADES_SYMBOL "\u2660"
|
|
||||||
#define HEARTS_SYMBOL "\u2665"
|
|
||||||
#define CLUBS_SYMBOL "\u2663"
|
|
||||||
|
|
||||||
#define BLACK_ON_WHITE 1
|
#define BLACK_ON_WHITE 1
|
||||||
#define RED_ON_WHITE 2
|
#define RED_ON_WHITE 2
|
||||||
#define WHITE_ON_BLUE 3
|
#define WHITE_ON_BLUE 3
|
||||||
|
Loading…
Reference in New Issue
Block a user