]> git.cworth.org Git - wordgame/blobdiff - grid.c
Increase the window size a bit
[wordgame] / grid.c
diff --git a/grid.c b/grid.c
index 273a6e83e765cb28c2ac291a17766e3ee1249b16..86aee9cbcb4d7ee81d63e1874a42db7f4ded1e9a 100644 (file)
--- a/grid.c
+++ b/grid.c
@@ -1,7 +1,7 @@
 /*
  * Copyright © 2006 Carl Worth
  *
- * This program is free software; you can redistribute it and\/or modify
+ * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
@@ -86,6 +86,31 @@ grid_init (grid_t *grid, int size)
            cubes_source[cubes[i]][rand_within(6)];
 }
 
+void
+grid_set_letters (grid_t       *grid,
+                 const char    *letters)
+{
+    int i;
+    int num_cubes = grid->size * grid->size;
+    char letter;
+
+    if (strlen (letters) != num_cubes) {
+       fprintf (stderr, "Error: Invalid string for %dx%d grid. Expected %d letters: %s\n",
+                grid->size, grid->size, num_cubes, letters);
+       exit (1);
+    }
+
+    for (i = 0; i < num_cubes; i++) {
+       letter = tolower (letters[i]);
+       if (letter < 'a' || letter > 'z') {
+           fprintf (stderr, "Error: Invalid character '%c' in letters: %s\n",
+                    letters[i], letters);
+           exit (1);
+       }
+       grid->letters[i / grid->size][i % grid->size] = letter;
+    }
+}
+
 char *
 grid_string (grid_t *grid)
 {