From: Laurent MAZET Date: Thu, 19 Dec 2024 14:31:59 +0000 (+0100) Subject: add title level X-Git-Tag: v1.0~7 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=f8a3b769754f10fe79cfc5ea1964eeaa9a61fec3;p=sokoban.git add title level --- diff --git a/display.c b/display.c index 22d857f..75ec61f 100644 --- a/display.c +++ b/display.c @@ -289,8 +289,11 @@ void boardwindow (board_t *board) set_color (white); _dobound (board->xsize, board->ysize, board->xoffset, board->yoffset); + if (board->title) { + _displaytitle (board->title, board->xoffset, board->yoffset - 1); + } - for (i = 0; i < board->width; i++) { + for (i = 0; i < board->width; i++) { for (j = 0; j < board->height; j++) { _element (board, i, j, getvalue (board, i, j)); } diff --git a/function.c b/function.c index c6ea897..0e81095 100644 --- a/function.c +++ b/function.c @@ -33,6 +33,7 @@ board_t *initboard (int width, int height) board->tab = (char *) calloc (1, width * height + 1); CHECKALLOC (board->tab); memset (board->tab, ' ', width * height); + board->title = NULL; board->scale = 0; board->xsize = board->width = width; board->ysize = board->height = height; @@ -47,6 +48,9 @@ board_t *copyboard (board_t *board) CHECKALLOC (board); memcpy (newboard, board, sizeof (board_t)); newboard->tab = (char *) calloc (1, board->width * board->height + 1); + if (board->title) { + newboard->title = strdup (board->title); + } CHECKALLOC (newboard->tab); memcpy (newboard->tab, board->tab, board->width * board->height + 1); return newboard; @@ -80,6 +84,7 @@ void freeboard (board_t *board) { if (board) { free (board->tab); + free (board->title); } free (board); } @@ -174,6 +179,7 @@ board_t *loadboard (char *str) int width = 0; int height = 0; char *tab = NULL; + char *title = NULL; char *saveptr1, *saveptr2; @@ -193,6 +199,8 @@ board_t *loadboard (char *str) height = atoi (value); } else if (strcmp (keyword, "tab") == 0) { tab = atos (value); + } else if (strcmp (keyword, "title") == 0) { + title = atos (value); } else if (strcmp (keyword, "rem") == 0) { /* nothing to do with remark */ } else { @@ -206,6 +214,9 @@ board_t *loadboard (char *str) if ((tab) && (strlen (tab) == (size_t)(width * height))) { board = initboard (width, height); memcpy (board->tab, tab, width * height); + if (title) { + board->title = strdup (title); + } } return board; diff --git a/test.sok b/test.sok index 1b1a4e9..3ed58da 100644 --- a/test.sok +++ b/test.sok @@ -1,3 +1,4 @@ width: 7 height: 5 tab: "##### #@ # # #$#### $ ..########" +title: "Tutorial" diff --git a/type.h b/type.h index 34ea365..8014e1d 100644 --- a/type.h +++ b/type.h @@ -5,6 +5,7 @@ typedef struct { int width; int height; char *tab; + char *title; int scale; int xsize; int ysize;