chiark / gitweb /
`Copy' operation for Mines.
[sgt-puzzles.git] / mines.c
diff --git a/mines.c b/mines.c
index b2bc82ccb87094e33ebdd6a907f21b9cc988da93..7f7d316effa6fb99cd4f164ec69134c6f2f3a38d 100644 (file)
--- a/mines.c
+++ b/mines.c
@@ -10,8 +10,6 @@
  *       That hook can talk to the game_ui and set the cheated flag,
  *       and then make_move can avoid setting the `won' flag after that.
  *
- *  - timer
- * 
  *  - question marks (arrgh, preferences?)
  * 
  *  - sensible parameter constraints
@@ -257,6 +255,8 @@ static char *validate_params(game_params *params)
        return "Width must be greater than zero";
     if (params->h <= 0)
        return "Height must be greater than zero";
+    if (params->n > params->w * params->h - 9)
+       return "Too many mines for grid size";
 
     /*
      * FIXME: Need more constraints here. Not sure what the
@@ -2174,7 +2174,30 @@ static game_state *solve_game(game_state *state, game_aux_info *aux,
 
 static char *game_text_format(game_state *state)
 {
-    return NULL;
+    char *ret;
+    int x, y;
+
+    ret = snewn((state->w + 1) * state->h + 1, char);
+    for (y = 0; y < state->h; y++) {
+       for (x = 0; x < state->w; x++) {
+           int v = state->grid[y*state->w+x];
+           if (v == 0)
+               v = '-';
+           else if (v >= 1 && v <= 8)
+               v = '0' + v;
+           else if (v == -1)
+               v = '*';
+           else if (v == -2 || v == -3)
+               v = '?';
+           else if (v >= 64)
+               v = '!';
+           ret[y * (state->w+1) + x] = v;
+       }
+       ret[y * (state->w+1) + state->w] = '\n';
+    }
+    ret[(state->w + 1) * state->h] = '\0';
+
+    return ret;
 }
 
 struct game_ui {
@@ -2700,6 +2723,13 @@ static int game_wants_statusbar(void)
     return TRUE;
 }
 
+static int game_timing_state(game_state *state)
+{
+    if (state->dead || state->won || !state->layout->mines)
+       return FALSE;
+    return TRUE;
+}
+
 #ifdef COMBINED
 #define thegame mines
 #endif
@@ -2721,7 +2751,7 @@ const struct game thegame = {
     dup_game,
     free_game,
     FALSE, solve_game,
-    FALSE, game_text_format,
+    TRUE, game_text_format,
     new_ui,
     free_ui,
     make_move,
@@ -2733,4 +2763,5 @@ const struct game thegame = {
     game_anim_length,
     game_flash_length,
     game_wants_statusbar,
+    TRUE, game_timing_state,
 };