int hx, hy, hradius; /* for mouse-down highlights */
int validradius;
int flash_is_death;
- int deaths;
+ int deaths, completed;
};
static game_ui *new_ui(game_state *state)
ui->hx = ui->hy = -1;
ui->hradius = ui->validradius = 0;
ui->deaths = 0;
+ ui->completed = FALSE;
ui->flash_is_death = FALSE; /* *shrug* */
return ui;
}
{
char buf[80];
/*
- * The deaths counter needs preserving across a serialisation.
+ * The deaths counter and completion status need preserving
+ * across a serialisation.
*/
sprintf(buf, "D%d", ui->deaths);
+ if (ui->completed)
+ strcat(buf, "C");
return dupstr(buf);
}
static void decode_ui(game_ui *ui, char *encoding)
{
- sscanf(encoding, "D%d", &ui->deaths);
+ int p= 0;
+ sscanf(encoding, "D%d%n", &ui->deaths, &p);
+ if (encoding[p] == 'C')
+ ui->completed = TRUE;
}
static void game_changed_state(game_ui *ui, game_state *oldstate,
game_state *newstate)
{
+ if (newstate->won)
+ ui->completed = TRUE;
}
struct game_drawstate {
- int w, h, started, tilesize;
+ int w, h, started, tilesize, bg;
signed char *grid;
/*
* Items in this `grid' array have all the same values as in
ds->started = FALSE;
ds->tilesize = 0; /* not decided yet */
ds->grid = snewn(ds->w * ds->h, signed char);
+ ds->bg = -1;
memset(ds->grid, -99, ds->w * ds->h);
(abs(x-ui->hx) <= ui->hradius && abs(y-ui->hy) <= ui->hradius))
v -= 20;
- if (ds->grid[y*ds->w+x] != v || bg != COL_BACKGROUND) {
+ if (ds->grid[y*ds->w+x] != v || bg != ds->bg) {
draw_tile(fe, ds, COORD(x), COORD(y), v, bg);
- ds->grid[y*ds->w+x] = (bg == COL_BACKGROUND ? v : -10);
+ ds->grid[y*ds->w+x] = v;
}
}
+ ds->bg = bg;
if (!state->layout->mines)
mines = state->layout->n;
return TRUE;
}
-static int game_timing_state(game_state *state)
+static int game_timing_state(game_state *state, game_ui *ui)
{
- if (state->dead || state->won || !state->layout->mines)
+ if (state->dead || state->won || ui->completed || !state->layout->mines)
return FALSE;
return TRUE;
}