aboutsummaryrefslogtreecommitdiff
path: root/mines.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2005-07-10 10:17:13 +0000
committerSimon Tatham <anakin@pobox.com>2005-07-10 10:17:13 +0000
commit3d2c442bc42050af618706899314414248126476 (patch)
treecadfacf9b241b06145d08d5cd6100cc22ddcafad /mines.c
parent145301d0dc5b75a89620ffe88bc8a890699eef59 (diff)
downloadpuzzles-3d2c442bc42050af618706899314414248126476.zip
puzzles-3d2c442bc42050af618706899314414248126476.tar.gz
puzzles-3d2c442bc42050af618706899314414248126476.tar.bz2
puzzles-3d2c442bc42050af618706899314414248126476.tar.xz
game_timing_state() now has access to the game_ui. This means that
whether the timer is currently going is no longer solely dependent on the current game_state: it can be dependent on more persistent information stored in the game_ui. In particular, Mines now freezes the timer permanently once you complete a grid for the first time, so that you can then backtrack through your solution process without destroying the information about how long it took you the first time through. [originally from svn r6088]
Diffstat (limited to 'mines.c')
-rw-r--r--mines.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/mines.c b/mines.c
index cf32064..f962dd6 100644
--- a/mines.c
+++ b/mines.c
@@ -2336,7 +2336,7 @@ struct game_ui {
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)
@@ -2345,6 +2345,7 @@ 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;
}
@@ -2358,20 +2359,28 @@ static char *encode_ui(game_ui *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;
+ 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 {
@@ -3015,9 +3024,9 @@ static int game_wants_statusbar(void)
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;
}