X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/0a6892dbcbd8ecb9be7e88a0368926fe521ae479..5c9f61fd500f6fd53a9f33721a1e66b9d5e1d9cc:/mines.c?ds=inline diff --git a/mines.c b/mines.c index 6aee39f..6cfb634 100644 --- a/mines.c +++ b/mines.c @@ -1946,7 +1946,7 @@ static char *new_mine_layout(int w, int h, int n, int x, int y, int unique, } static char *new_game_desc(game_params *params, random_state *rs, - game_aux_info **aux, int interactive) + char **aux, int interactive) { /* * We generate the coordinates of an initial click even if they @@ -1984,17 +1984,13 @@ static char *new_game_desc(game_params *params, random_state *rs, } } -static void game_free_aux_info(game_aux_info *aux) -{ - assert(!"Shouldn't happen"); -} - static char *validate_desc(game_params *params, char *desc) { int wh = params->w * params->h; int x, y; if (*desc == 'r') { + desc++; if (!*desc || !isdigit((unsigned char)*desc)) return "No initial mine count in game description"; while (*desc && isdigit((unsigned char)*desc)) @@ -2298,7 +2294,7 @@ static void free_game(game_state *state) } static char *solve_game(game_state *state, game_state *currstate, - game_aux_info *aux, char **error) + char *aux, char **error) { if (!state->layout->mines) { *error = "Game has not been started yet"; @@ -2357,6 +2353,21 @@ static void free_ui(game_ui *ui) sfree(ui); } +static char *encode_ui(game_ui *ui) +{ + char buf[80]; + /* + * The deaths counter needs preserving across a serialisation. + */ + sprintf(buf, "D%d", ui->deaths); + return dupstr(buf); +} + +static void decode_ui(game_ui *ui, char *encoding) +{ + sscanf(encoding, "D%d", &ui->deaths); +} + static void game_changed_state(game_ui *ui, game_state *oldstate, game_state *newstate) { @@ -2596,19 +2607,19 @@ static game_state *execute_move(game_state *from, char *move) static void game_size(game_params *params, game_drawstate *ds, int *x, int *y, int expand) { - int tsx, tsy, ts; + double tsx, tsy, ts; /* * Each window dimension equals the tile size times 3 more than * the grid dimension (the border is 3/2 the width of the * tiles). */ - tsx = *x / (params->w + 3); - tsy = *y / (params->h + 3); + tsx = (double)*x / ((double)params->w + 3.0); + tsy = (double)*y / ((double)params->h + 3.0); ts = min(tsx, tsy); if (expand) - ds->tilesize = ts; + ds->tilesize = (int)(ts + 0.5); else - ds->tilesize = min(ts, PREFERRED_TILE_SIZE); + ds->tilesize = min((int)ts, PREFERRED_TILE_SIZE); *x = BORDER * 2 + TILE_SIZE * params->w; *y = BORDER * 2 + TILE_SIZE * params->h; @@ -3030,7 +3041,6 @@ const struct game thegame = { TRUE, game_configure, custom_params, validate_params, new_game_desc, - game_free_aux_info, validate_desc, new_game, dup_game, @@ -3039,6 +3049,8 @@ const struct game thegame = { TRUE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, game_changed_state, interpret_move, execute_move,