From: Carl Worth Date: Sat, 23 Sep 2006 08:31:48 +0000 (-0700) Subject: Fix games wiithout time limit. Don't add empty repsonse to history. Don't expect... X-Git-Url: https://git.cworth.org/git?p=wordgame;a=commitdiff_plain;h=a6f9c10c08f706c3c25ab81fef956339490e50f3 Fix games wiithout time limit. Don't add empty repsonse to history. Don't expect puzzle to end in newline. --- diff --git a/grid.c b/grid.c index ed88df3..76428d9 100644 --- a/grid.c +++ b/grid.c @@ -97,7 +97,8 @@ board_to_string (board_t *board, else *s++ = ' '; } - *s++ = '\n'; + if (y != 3) + *s++ = '\n'; } *s = '\0'; } diff --git a/word-game.c b/word-game.c index 29cf01b..8c9af9a 100644 --- a/word-game.c +++ b/word-game.c @@ -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);