]> git.cworth.org Git - wordgame/commitdiff
Add verification of the word
authorCarl Worth <cworth@cworth.org>
Mon, 18 Dec 2006 16:12:05 +0000 (08:12 -0800)
committerCarl Worth <cworth@cworth.org>
Mon, 18 Dec 2006 16:12:05 +0000 (08:12 -0800)
Currently just printing to stdout, no yet providing graphical verification.

rack-fancy.c

index bd9f83caca55db91530eaf99563694208dadca08..63677da3d52594a37b995256854ccfca8ea5a2ca 100644 (file)
@@ -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,