From 126ad5fb638310f5a81804fea205e9ad9cab0cae Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Sat, 1 Jun 2024 15:24:06 +0200 Subject: [PATCH] add more languages --- bag-de.h | 14 +++++----- bag-es.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ bag-it.h | 60 ++++++++++++++++++++++++++++++++++++++++++ bag-nl.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ constant.c | 34 ++++++++++++++++++++++++ constant.h | 2 ++ display.c | 32 ++++++++++++++--------- display.h | 2 +- scrabble.c | 2 +- 9 files changed, 276 insertions(+), 20 deletions(-) create mode 100644 bag-es.h create mode 100644 bag-it.h create mode 100644 bag-nl.h diff --git a/bag-de.h b/bag-de.h index fca3c9e..9b05f9c 100644 --- a/bag-de.h +++ b/bag-de.h @@ -27,11 +27,11 @@ static char _tiles_de[NB_TILES_DE] = { 'F', 'F', 'K', 'K', 'P', - 'Ä', + 'a', /* 'Ä' */ 'J', - 'Ü', + 'u', /* 'Ü' */ 'V', - 'Ö', + 'o', /* 'Ö' */ 'X', 'Q', 'Y' @@ -61,16 +61,18 @@ static lettervalue_t _lettervalues_de[NB_LETTERVALUES_DE] = { {'F', 4}, {'K', 4}, {'P', 4}, - {'Ä', 6}, + {'a' /* 'Ä' */, 6}, {'J', 6}, - {'Ü', 6}, + {'u' /* 'Ü' */, 6}, {'V', 6}, - {'Ö', 8}, + {'o' /* 'Ö' */, 8}, {'X', 8}, {'Q', 10}, {'Y', 10} }; +static char *_extra_help_de = "a, u, o for AE, UE, OE"; + #endif /* __BAG_DE__ */ /* vim: set ts=4 sw=4 et: */ diff --git a/bag-es.h b/bag-es.h new file mode 100644 index 0000000..974f396 --- /dev/null +++ b/bag-es.h @@ -0,0 +1,76 @@ +#ifndef __BAG_ES__ +#define __BAG_ES__ + +#include "type.h" + +#define NB_TILES_ES 100 +static char _tiles_es[NB_TILES_ES] = { + '.', '.', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', + 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', + 'I', 'I', 'I', 'I', 'I', 'I', + 'S', 'S', 'S', 'S', 'S', 'S', + 'N', 'N', 'N', 'N', 'N', + 'R', 'R', 'R', 'R', 'R', + 'U', 'U', 'U', 'U', 'U', + 'L', 'L', 'L', 'L', + 'T', 'T', 'T', 'T', + 'D', 'D', 'D', 'D', 'D', + 'G', 'G', + 'C', 'C', 'C', 'C', + 'B', 'B', + 'M', 'M', + 'P', 'P', + 'H', 'H', + 'F', + 'V', + 'Y', + 'c', /* 'CH' */ + 'Q', + 'J', + 'l', /* 'LL' */ + 'n', /* 'Ñ' */ + 'r', /* 'RR' */ + 'X', + 'Z' +}; + +#define NB_LETTERVALUES_ES 29 +static lettervalue_t _lettervalues_es[NB_LETTERVALUES_ES] = { + {'.', 0}, + {'A', 1}, + {'E', 1}, + {'O', 1}, + {'I', 1}, + {'S', 1}, + {'N', 1}, + {'R', 1}, + {'U', 1}, + {'L', 1}, + {'T', 1}, + {'D', 2}, + {'G', 2}, + {'C', 3}, + {'B', 3}, + {'M', 3}, + {'P', 3}, + {'H', 4}, + {'F', 4}, + {'V', 4}, + {'Y', 4}, + {'c' /* 'CH' */, 5}, + {'Q', 5}, + {'J', 8}, + {'l' /* 'LL' */ , 8}, + {'n' /* 'Ñ' */, 8}, + {'r' /* 'RR' */, 8}, + {'X', 8}, + {'Z', 10} +}; + +static char *_extra_help_es = "c, l, n, r for CH, LL, NN, RR"; + +#endif /* __BAG_ES__ */ + +/* vim: set ts=4 sw=4 et: */ diff --git a/bag-it.h b/bag-it.h new file mode 100644 index 0000000..cfeef03 --- /dev/null +++ b/bag-it.h @@ -0,0 +1,60 @@ +#ifndef __BAG_IT__ +#define __BAG_IT__ + +#include "type.h" + +#define NB_TILES_IT 120 +static char _tiles_it[NB_TILES_IT] = { + '.', '.', + 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', + 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', + 'C', 'C', 'C', 'C', 'C', 'C', + 'R', 'R', 'R', 'R', 'R', 'R', + 'S', 'S', 'S', 'S', 'S', 'S', + 'T', 'T', 'T', 'T', 'T', 'T', + 'L', 'L', 'L', 'L', 'L', + 'M', 'M', 'M', 'M', 'M', + 'N', 'N', 'N', 'N', 'N', + 'U', 'U', 'U', 'U', 'U', + 'B', 'B', 'B', + 'D', 'D', 'D', + 'F', 'F', 'F', + 'P', 'P', 'P', + 'V', 'V', 'V', + 'G', 'G', + 'H', 'H', + 'Z', 'Z', + 'Q' +}; + +#define NB_LETTERVALUES_IT 22 +static lettervalue_t _lettervalues_it[NB_LETTERVALUES_IT] = { + {'.', 0}, + {'O', 1}, + {'A', 1}, + {'I', 1}, + {'E', 1}, + {'C', 2}, + {'R', 2}, + {'S', 2}, + {'T', 2}, + {'L', 3}, + {'M', 3}, + {'N', 3}, + {'U', 3}, + {'B', 5}, + {'D', 5}, + {'F', 5}, + {'P', 5}, + {'V', 5}, + {'G', 8}, + {'H', 8}, + {'Z', 8}, + {'Q', 10} +}; + +#endif /* __BAG_IT__ */ + +/* vim: set ts=4 sw=4 et: */ diff --git a/bag-nl.h b/bag-nl.h new file mode 100644 index 0000000..cd6794f --- /dev/null +++ b/bag-nl.h @@ -0,0 +1,74 @@ +#ifndef __BAG_NL__ +#define __BAG_NL__ + +#include "type.h" + +#define NB_TILES_NL 102 +static char _tiles_nl[NB_TILES_NL] = { + '.', '.', + 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', + 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', + 'A', 'A', 'A', 'A', 'A', 'A', + 'O', 'O', 'O', 'O', 'O', 'O', + 'I', 'I', 'I', 'I', + 'D', 'D', 'D', 'D', 'D', + 'R', 'R', 'R', 'R', 'R', + 'T', 'T', 'T', 'T', 'T', + 'S', 'S', 'S', 'S', + 'G', 'G', 'G', + 'K', 'K', 'K', + 'L', 'L', 'L', + 'M', 'M', 'M', + 'B', 'B', + 'P', 'P', + 'U', 'U', 'U', + 'H', 'H', + 'J', 'J', + 'V', 'V', + 'Z', 'Z', + 'i', 'i', /* IJ */ + 'F', + 'C', 'C', + 'W', 'W', + 'X', + 'Y', + 'Q' +}; + +#define NB_LETTERVALUES_NL 28 +static lettervalue_t _lettervalues_nl[NB_LETTERVALUES_NL] = { + {'.', 0}, + {'E', 1}, + {'N', 1}, + {'A', 1}, + {'O', 1}, + {'I', 1}, + {'D', 2}, + {'R', 2}, + {'T', 2}, + {'S', 2}, + {'G', 3}, + {'K', 3}, + {'L', 3}, + {'M', 3}, + {'B', 3}, + {'P', 3}, + {'U', 4}, + {'H', 4}, + {'J', 4}, + {'V', 4}, + {'Z', 4}, + {'i' /* 'IJ */, 4}, + {'F', 4}, + {'C', 5}, + {'W', 5}, + {'X', 8}, + {'Y', 8}, + {'Q', 10} +}; + +static char *_extra_help_nl = "i for IJ"; + +#endif /* __BAG_NL__ */ + +/* vim: set ts=4 sw=4 et: */ diff --git a/constant.c b/constant.c index 390ec7d..a8fc214 100644 --- a/constant.c +++ b/constant.c @@ -28,8 +28,11 @@ board_t *getboard (char *name) } #include "bag-de.h" +#include "bag-es.h" #include "bag-en.h" #include "bag-fr.h" +#include "bag-it.h" +#include "bag-nl.h" static bag_t _bag = {0}; @@ -49,15 +52,46 @@ bag_t *getbag (char *lang) pt->tiles = _tiles_en; pt->nbletters = NB_LETTERVALUES_EN; pt->lettervalues = _lettervalues_en; + } else if (strcmp (lang, "es") == 0) { + pt = &_bag; + pt->nbtiles = NB_TILES_ES; + pt->tiles = _tiles_es; + pt->nbletters = NB_LETTERVALUES_ES; + pt->lettervalues = _lettervalues_es; } else if (strcmp (lang, "fr") == 0) { pt = &_bag; pt->nbtiles = NB_TILES_FR; pt->tiles = _tiles_fr; pt->nbletters = NB_LETTERVALUES_FR; pt->lettervalues = _lettervalues_fr; + } else if (strcmp (lang, "it") == 0) { + pt = &_bag; + pt->nbtiles = NB_TILES_IT; + pt->tiles = _tiles_it; + pt->nbletters = NB_LETTERVALUES_IT; + pt->lettervalues = _lettervalues_it; + } else if (strcmp (lang, "nl") == 0) { + pt = &_bag; + pt->nbtiles = NB_TILES_NL; + pt->tiles = _tiles_nl; + pt->nbletters = NB_LETTERVALUES_NL; + pt->lettervalues = _lettervalues_nl; } return pt; } +char *getextrahelp (char *lang) +{ + char *pt = NULL; + if (strcmp (lang, "de") == 0) { + pt = _extra_help_de; + } else if (strcmp (lang, "es") == 0) { + pt = _extra_help_es; + } else if (strcmp (lang, "nl") == 0) { + pt = _extra_help_nl; + } + return pt; +} + /* vim: set ts=4 sw=4 et: */ diff --git a/constant.h b/constant.h index 5cb82ff..1d7f0f4 100644 --- a/constant.h +++ b/constant.h @@ -7,6 +7,8 @@ board_t *getboard (char *name); bag_t *getbag (char *lang); +char *getextrahelp (char *lang); + #endif /* __CONSTANT_H__ */ /* vim: set ts=4 sw=4 et: */ diff --git a/display.c b/display.c index db14c78..ac2b682 100644 --- a/display.c +++ b/display.c @@ -120,19 +120,11 @@ void showboard (play_t *play, board_t *board, int xoffset, int yoffset, int full } } -void helpwindow (char *msg, int xoffset, int yoffset, int length) +int _helpwindow (char *msg, int xoffset, int yoffset, int length) { - char *title = "Help message"; - int i; - - for (i = 0; (i < length) && (title[i] != '\0'); i++) { - mvaddch (yoffset , xoffset + i, title[i]); - mvaddch (yoffset + 1, xoffset + i, ACS_HLINE); - } - - i = 0; - int j = 2; - while (*msg != '\0') { + int i = 0; + int j = 0; + while ((msg) && (*msg != '\0')) { if ((*msg == '\n') || (i == length)) { i = 0; j++; @@ -143,6 +135,22 @@ void helpwindow (char *msg, int xoffset, int yoffset, int length) } msg++; } + return j; +} + +void helpwindow (char *msg, char *msg2, int xoffset, int yoffset, int length) +{ + char *title = "Help message"; + int i; + + for (i = 0; (i < length) && (title[i] != '\0'); i++) { + mvaddch (yoffset , xoffset + i, title[i]); + mvaddch (yoffset + 1, xoffset + i, ACS_HLINE); + } + int j = 2; + j += _helpwindow (msg, xoffset, yoffset + j, length); + j++; + j += _helpwindow (msg2, xoffset, yoffset + j, length); } void valuewindow (bag_t *bag, int xoffset, int yoffset, int length) diff --git a/display.h b/display.h index 6e817fb..66d8189 100644 --- a/display.h +++ b/display.h @@ -9,7 +9,7 @@ void showletter (char letter, int x, int y, int mode); void showboard (play_t *play, board_t *board, int xoffset, int yoffset, int full); -void helpwindow (char *msg, int xoffset, int yoffset, int length); +void helpwindow (char *msg, char *msg2, int xoffset, int yoffset, int length); void valuewindow (bag_t *bag, int xoffset, int yoffset, int length); diff --git a/scrabble.c b/scrabble.c index 206a1c9..474311c 100644 --- a/scrabble.c +++ b/scrabble.c @@ -145,7 +145,7 @@ int main (int argc, char *argv[]) int ydrawwin = 2 * yoffset + max (board->ysize, 1 + (bag->nbletters + 1) /2); valuewindow (bag, xvaluewin, yvaluewin, 10); - helpwindow (help, xhelpwin, yhelpwin, 30); + helpwindow (help, getextrahelp (language), xhelpwin, yhelpwin, 30); int mode = 0; showboard (play, board, xoffset, yoffset, mode); -- 2.30.2