clean message display
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 9 Sep 2024 09:24:07 +0000 (11:24 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 9 Sep 2024 09:24:07 +0000 (11:24 +0200)
display.c
snake.c

index 4e9ba2d9022cf408ff1b985b441fca06b09691cb..2e6bd34becc2c3ffd38f7ecc7fb1fc395cd0d992 100644 (file)
--- a/display.c
+++ b/display.c
@@ -243,16 +243,10 @@ void msgwindow (char *msg, int xoffset, int yoffset, int length)
 
 void msg2window (char *msg, int xoffset, int yoffset)
 {
-    int i;
-    setcolor (gray_black);
     int length = strlen (msg) + 2;
     xoffset -= length / 2;
-    _dobound (length, 1, xoffset, yoffset);
-    for (i = 0; i < length; i++) {
-        mvaddch (yoffset, xoffset + i, ' ');
-    }
-    mvaddstr (yoffset, xoffset + 1, msg);
-    setcolor (black_gray);
+    yoffset -= strmaxlen (msg, '\n') / 2;
+    msgwindow (msg, xoffset, yoffset, length);
 }
 
 void displaysnake (board_t *board, snake_t *snake)
diff --git a/snake.c b/snake.c
index 222a305a066d2f2ab617e543442ca8e16aaf1e1e..5e8aa3ee003e6916b6355b59839f76dbf7879096 100644 (file)
--- a/snake.c
+++ b/snake.c
@@ -168,8 +168,9 @@ int main (int argc, char *argv[])
     int yboard = board->yoffset = yoffset + 1;
     int xscore = xboard + xoffset + 2 + board->xsize;
     int yscore = yboard;
+    int wscore = whelp - 2;
     int xhelp = xscore - 1;
-    int yhelp = yscore + 3 + xoffset;
+    int yhelp = yscore + 2 + xoffset;
     int xsave = max (xboard + (board->xsize - savelen) / 2, 1);
     int ysave = yboard + (board->ysize - 1) / 2;
     char *savename = NULL;
@@ -181,8 +182,8 @@ int main (int argc, char *argv[])
 
     /* window positions (msg) */
     int xmsg = xhelp + 1;
-    int ymsg = yhelp + lhelp + xoffset;
-    int lmsg = strmaxlen (help, '\n') - 2;
+    int ymsg = yhelp + lhelp + 1 + xoffset;
+    int lmsg = whelp - 2;
 
     /* main loop */
     int nonewpoint = 1;
@@ -241,7 +242,7 @@ int main (int argc, char *argv[])
             setcolor (red_black);
             break;
         }
-        scorewindow (xscore, yscore, whelp - 2, score, duration / 1000);
+        scorewindow (xscore, yscore, wscore, score, duration / 1000);
         setcolor (gray_black);
 
         /* message */