From 350683b25371ec6a7548b2e83b2be15eb629815f Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 19 May 2004 11:57:09 +0000 Subject: Introduce routines in each game module to encode a set of game parameters as a string, and decode it again. This is used in midend.c to prepend the game parameters to the game seed, so that copying out of the Specific box is sufficient to completely specify the game you were playing. Throughout development of these games I have referred to `seed' internally, and `game ID' externally. Now there's a measurable difference between them! :-) [originally from svn r4231] --- rect.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'rect.c') diff --git a/rect.c b/rect.c index dcd8ef7..9b7816c 100644 --- a/rect.c +++ b/rect.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "puzzles.h" @@ -129,6 +130,29 @@ game_params *dup_params(game_params *params) return ret; } +game_params *decode_params(char const *string) +{ + game_params *ret = default_params(); + + ret->w = ret->h = atoi(string); + while (*string && isdigit(*string)) string++; + if (*string == 'x') { + string++; + ret->h = atoi(string); + } + + return ret; +} + +char *encode_params(game_params *params) +{ + char data[256]; + + sprintf(data, "%dx%d", params->w, params->h); + + return dupstr(data); +} + config_item *game_configure(game_params *params) { config_item *ret; -- cgit v1.1