]> git.cworth.org Git - wordgame/blobdiff - word-game.c
Fix games wiithout time limit. Don't add empty repsonse to history. Don't expect...
[wordgame] / word-game.c
index 29cf01bdd9fcb0ed1d109d2662e9b8d754cf5ee9..8c9af9a59071feda5567f90cfecea9f014f32083 100644 (file)
@@ -82,7 +82,7 @@ word_game_play (const char    *puzzle,
     for (i=0; i < 17; i++)
        possible_total += possible[i];
 
-    printf ("%s\n", puzzle);
+    printf ("%s\n\n", puzzle);
     just_saw_puzzle = TRUE;
 
     remaining = time_limit_seconds;
@@ -92,6 +92,7 @@ word_game_play (const char    *puzzle,
        tv_stop.tv_sec += time_limit_seconds;
     } else {
        sprintf (prompt, "> ");
+       remaining = 1;
     }
     do {
        if (time_limit_seconds) {
@@ -100,10 +101,11 @@ word_game_play (const char        *puzzle,
            sprintf (prompt, "%02d:%02d ", minutes, seconds);
        }
        response = readline (prompt);
-       add_history (response);
+       if (response == NULL)
+           break;
        if (strlen (response) == 0) {
            if (! just_saw_puzzle) {
-               printf ("%s\n", puzzle);
+               printf ("%s\n\n", puzzle);
                just_saw_puzzle = TRUE;
            } else {
                for (i = 2; i <= 17; i++)
@@ -116,6 +118,7 @@ word_game_play (const char  *puzzle,
        } else {
            dict_entry_t *entry;
            just_saw_puzzle = FALSE;
+           add_history (response);
            if (response[strlen (response) - 1] == '\n')
                response[strlen (response) - 1] = '\0';
            entry = dict_lookup (answers, response);
@@ -143,7 +146,7 @@ word_game_play (const char  *puzzle,
        }
     } while (remaining > 0);
 
-    printf ("%s\n", puzzle);
+    printf ("%s\n\n", puzzle);
 
     printf ("Words you found:\n");
     dict_print_by_length_if (answers, seen_predicate);