]> git.cworth.org Git - wordgame/blobdiff - rack-fancy.c
Only show solution words after found (with refresh bug)
[wordgame] / rack-fancy.c
index bd9f83caca55db91530eaf99563694208dadca08..f2caa13adae6daa53bd43cf896903fda61598dde 100644 (file)
@@ -27,6 +27,7 @@
 #include "word-game.h"
 #include "demo-item.h"
 
+#define RACK_DICT_ENTRY_FOUND (1<<1)
 #define MAX_TILES 7
 
 typedef struct _tile
@@ -42,8 +43,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;
@@ -76,14 +78,20 @@ typedef struct _dict_paint_cursor
 } dict_paint_cursor_t;
 
 static void
-dict_paint_action (void *closure, char *word)
+dict_paint_action (void *closure, char *word, dict_entry_t *entry)
 {
     dict_paint_cursor_t *cursor = closure;
     cairo_t *cr = cursor->cr;
     double new_x, new_y;
 
     cairo_move_to (cr, cursor->x, cursor->y);
-    cairo_show_text (cr, word);
+    if (*entry & RACK_DICT_ENTRY_FOUND) {
+       cairo_show_text (cr, word);
+    } else {
+       int i, length = strlen (word);
+       for (i = 0; i < length; i++)
+           cairo_show_text (cr, "_");
+    }
     cairo_get_current_point (cr, &new_x, &new_y);
     if (new_x > cursor->max_column_width)
        cursor->max_column_width = new_x;
@@ -242,7 +250,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 +260,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 +292,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 +305,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 +318,14 @@ 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)) {
+           *entry = *entry | RACK_DICT_ENTRY_FOUND;
+           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 +369,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 +418,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,