From: Laurent MAZET Date: Fri, 7 Jun 2024 13:43:08 +0000 (+0200) Subject: display score X-Git-Tag: v1.0~37 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=fa31aa0a346f1fd1a4142ebbd2f572858ef57818;p=scrabble.git display score --- diff --git a/display.c b/display.c index df37cc4..6c7a2af 100644 --- a/display.c +++ b/display.c @@ -138,11 +138,12 @@ int _helpwindow (char *msg, int xoffset, int yoffset, int length) return j; } -void helpwindow (char *msg, char *msg2, int xoffset, int yoffset, int length) +int helpwindow (char *msg, char *msg2, int xoffset, int yoffset) { char *title = "Help message"; - int i; + int length = strmaxlen (msg, '\n'); + int i; for (i = 0; (i < length) && (title[i] != '\0'); i++) { mvaddch (yoffset , xoffset + i, title[i]); mvaddch (yoffset + 1, xoffset + i, ACS_HLINE); @@ -151,6 +152,8 @@ void helpwindow (char *msg, char *msg2, int xoffset, int yoffset, int length) j += _helpwindow (msg, xoffset, yoffset + j, length); j++; j += _helpwindow (msg2, xoffset, yoffset + j, length); + + return length; } void valuewindow (bag_t *bag, int xoffset, int yoffset, int length, char current) @@ -204,4 +207,17 @@ void drawwindow (draw_t *game, int xoffset, int yoffset) set_color (white); } +void scorewindow (int score, int xoffset, int yoffset) +{ + char *title = "Score"; + int i; + for (i = 0; title[i] != '\0'; i++) { + mvaddch (yoffset, xoffset + i, title[i]); + mvaddch (yoffset + 1, xoffset + i, ACS_HLINE); + } + char str[12] = {0}; + sprintf (str, " % 3d", score); + mvaddstr (yoffset + 2, xoffset, str); +} + /* vim: set ts=4 sw=4 et: */ diff --git a/display.h b/display.h index 85d754b..ae15e23 100644 --- a/display.h +++ b/display.h @@ -9,12 +9,14 @@ 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, char *msg2, int xoffset, int yoffset, int length); +int helpwindow (char *msg, char *msg2, int xoffset, int yoffset); void valuewindow (bag_t *bag, int xoffset, int yoffset, int length, char current); void drawwindow (draw_t *game, int xoffset, int yoffset); +void scorewindow (int score, int xoffset, int yoffset); + #endif /* __DISPLAY_H__ */ /* vim: set ts=4 sw=4 et: */ diff --git a/function.c b/function.c index 6a5ca6c..24b6f31 100644 --- a/function.c +++ b/function.c @@ -18,6 +18,30 @@ int contains (char *list, char *str) return 0; } +int strcount (char *str, char ch) +{ + int n = 0; + while ((str = strchr (str, ch)) != NULL) { + str++; + n++; + } + return n; +} + +int strmaxlen (char *str, char ch) +{ + int len = 0; + char *end = NULL; + while ((end = strchr (str, ch)) != NULL) { + int l = (int)(end - str); + if (l > len) { + len = l; + } + str = end + 1; + } + return len; +} + play_t *initplay (int xsize, int ysize) { play_t *play = (play_t *) malloc (sizeof (play_t)); diff --git a/function.h b/function.h index 6d70d63..f9dd4bf 100644 --- a/function.h +++ b/function.h @@ -5,6 +5,10 @@ int contains (char *list, char *str); +int strcount (char *str, char ch); + +int strmaxlen (char *str, char ch); + play_t *initplay (int xsize, int ysize); void freeplay (play_t *play); diff --git a/scrabble.c b/scrabble.c index 5d8abe6..41c0a8d 100644 --- a/scrabble.c +++ b/scrabble.c @@ -149,7 +149,10 @@ int main (int argc, char *argv[]) int xdrawwin = xoffset; int ydrawwin = 2 * yoffset + max (board->ysize, 1 + (bag->nbletters + 1) /2); - helpwindow (help, getextrahelp (language), xhelpwin, yhelpwin, 30); + int helplen = helpwindow (help, getextrahelp (language), xhelpwin, yhelpwin); + + int xscorewin = xhelpwin + helplen+ xoffset; + int yscorewin = yhelpwin; int mode = 0; showboard (play, board, xoffset, yoffset, mode); @@ -168,6 +171,7 @@ int main (int argc, char *argv[]) } showletter (highlight, x + xoffset, y + yoffset, 1); valuewindow (bag, xvaluewin, yvaluewin, 10, highlight); + scorewindow (score, xscorewin, yscorewin); switch (getch ()) { case '\t':