From: Mazet Laurent Date: Mon, 3 Jun 2024 05:24:18 +0000 (+0200) Subject: add board title X-Git-Tag: v1.0~9 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=deabc06366fb04d3953bc28704932d3719b05056;p=bs.git add board title --- diff --git a/battleships.c b/battleships.c index 9b2655b..7fcca9e 100644 --- a/battleships.c +++ b/battleships.c @@ -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 3552d28..5483dc0 100644 --- 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 56923bb..e2db5da 100644 --- 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); diff --git a/display.c b/display.c index b90ad6d..d3c7f7d 100644 --- 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)