add board title
authorMazet Laurent <mazet@softndesign.org>
Mon, 3 Jun 2024 05:24:18 +0000 (07:24 +0200)
committerMazet Laurent <mazet@softndesign.org>
Mon, 3 Jun 2024 05:24:18 +0000 (07:24 +0200)
battleships.c
board.c
board.h
display.c

index 9b2655bba5eb290ad1b0148334fe7396a982b9eb..7fcca9e631e6baadb4bd20e4f5b3f39a279cdf2b 100644 (file)
@@ -114,13 +114,13 @@ int main (int argc, char *argv[])
     int xlogs = xhuman;
     int ylogs = yhuman + ysize + 5;
 
-    board_t *boardcomputer = initboard (xsize, ysize);
+    board_t *boardcomputer = initboard ("Computer", xsize, ysize);
     int n = 0;
     while (boats[n] > 0) {
         drawship (boardcomputer, boats[n++]);
     }
 
-    board_t *boardhuman = initboard (xsize, ysize);
+    board_t *boardhuman = initboard ("Human", xsize, ysize);
     int x, y, orient;
     n = 0;
     int length = boats[n];
diff --git a/board.c b/board.c
index 3552d28d7c8e3d9d3bf4301a4b3d92046fbc9e9e..5483dc0fb84a7bc0d94002c9a9947b8852e5dfde 100644 (file)
--- a/board.c
+++ b/board.c
@@ -3,13 +3,14 @@
 
 #include "board.h"
 
-board_t *initboard (int xsize, int ysize)
+board_t *initboard (char *title, int xsize, int ysize)
 {
     board_t *board = (board_t *) malloc (sizeof (board_t));
     board->tab = (char *) malloc (xsize * ysize);
     memset (board->tab, ' ', xsize * ysize);
     board->xsize = xsize;
     board->ysize = ysize;
+    board->title = strdup (title);
     return board;
 }
 
diff --git a/board.h b/board.h
index 56923bb3201a3ccfbf5f0211e6f074a50abeecfb..e2db5da11ce968df65943e7220a306fa8aa6364e 100644 (file)
--- a/board.h
+++ b/board.h
@@ -5,9 +5,10 @@ typedef struct {
     int xsize;
     int ysize;
     char *tab;
+    char *title;
 } board_t;
 
-board_t *initboard (int xsize, int ysize);
+board_t *initboard (char *title, int xsize, int ysize);
 
 int testlocation (board_t *board, int length, int x, int y, int orient, char *symbs);
 
index b90ad6dce19599e547dba6d3bc985007b43ff14b..d3c7f7db54403d275446f1130afa2fd7a8484156 100644 (file)
--- a/display.c
+++ b/display.c
@@ -81,6 +81,10 @@ void displayboard (board_t *board, int xoffset, int yoffset, int mode, int show)
             setcolor (white);
         }
     }
+
+    setcolor (black);
+    mvaddstr (yoffset - 2, xoffset + (board->xsize - strlen (board->title)) / 2, board->title);
+    setcolor (white);
 }
 
 void displayelement (int length, int x, int y, int orient, char symb, int show)