From 4a18152043dd8fa417e5b8db7047de2e3998da7b Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 18 Dec 2006 08:12:05 -0800 Subject: [PATCH] Add verification of the word Currently just printing to stdout, no yet providing graphical verification. --- rack-fancy.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/rack-fancy.c b/rack-fancy.c index bd9f83c..63677da 100644 --- a/rack-fancy.c +++ b/rack-fancy.c @@ -42,8 +42,9 @@ typedef struct _rack { tile_t *tiles[MAX_TILES]; int num_tiles; - char guess[MAX_TILES]; + char guess[MAX_TILES+1]; int guess_length; + dict_t *solution; } rack_t; static rack_t the_rack; @@ -242,7 +243,7 @@ shuffle (int *array, int length) } static void -rack_init (rack_t *rack, GooCanvasItem *parent, char *word) +rack_init (rack_t *rack, GooCanvasItem *parent, char *word, dict_t *solution) { int i; @@ -252,6 +253,7 @@ rack_init (rack_t *rack, GooCanvasItem *parent, char *word) while (i < MAX_TILES) rack->tiles[i] = NULL; rack->guess_length = 0; + rack->solution = solution; } static gboolean @@ -283,6 +285,7 @@ rack_return_tile (rack_t *rack, tile_t *tile) tile_glide_to (tile, x, y); tile->guessed = FALSE; rack->guess_length--; + rack->guess[rack->guess_length] = '\0'; } static void @@ -295,6 +298,7 @@ rack_return_all (rack_t *rack) rack_return_tile (rack, rack->tiles[i]); } rack->guess_length = 0; + rack->guess[0] = '\0'; } static gboolean @@ -307,6 +311,12 @@ on_key_press_event (GtkWidget *widget, rack_t *rack = user_data; if (event->keyval == GDK_Return) { + dict_entry_t *entry; + entry = dict_lookup (rack->solution, rack->guess); + if (DICT_ENTRY_IS_WORD (entry)) + printf ("%s is good\n", rack->guess); + else + printf ("%s is not a word\n", rack->guess); rack_return_all (rack); return TRUE; } @@ -350,6 +360,7 @@ on_key_press_event (GtkWidget *widget, tile_glide_to (rack->tiles[i], x, y); rack->tiles[i]->guessed = TRUE; rack->guess[rack->guess_length++] = guess_letter; + rack->guess[rack->guess_length] = '\0'; return TRUE; } } @@ -398,7 +409,7 @@ create_canvas (GtkWidget *parent, char *word, dict_t *solution) root = goo_canvas_get_root_item (GOO_CANVAS (canvas)); - rack_init (&the_rack, root, word); + rack_init (&the_rack, root, word, solution); goo_demo_item_new (root, LETTER_PAD, -- 2.43.0