#include #include #include #include #include #include "rnd.h" #include "dir.h" #include "grid.h" enum exitcodes { EXIT_WORDTOOLONG, }; bounds *get_bounds(int height, int width, enum direction direction, int length) { if (length > height || length > width) { return NULL; } length--; bounds *b = (bounds *) malloc(sizeof(bounds)); b->min_x = 0; b->max_x = width-1; b->min_y = 0; b->max_y = height-1; if (direction == DIRECTION_N || direction == DIRECTION_NE || direction == DIRECTION_NW) { b->min_y = length; } if (direction == DIRECTION_W || direction == DIRECTION_NW || direction == DIRECTION_SW) { b->min_x = length; } if (direction == DIRECTION_E || direction == DIRECTION_NE || direction == DIRECTION_SE) { b->max_x = width - length; } if (direction == DIRECTION_S || direction == DIRECTION_SW || direction == DIRECTION_SE) { b->max_y = height - length; } return b; } int move_x(int x, enum direction d) { if( d == DIRECTION_E || d == DIRECTION_NE || d == DIRECTION_SE ) { x++; } else if ( d == DIRECTION_W || d == DIRECTION_NW || d == DIRECTION_SW ) { x--; } return x; } int move_y(int y, enum direction d) { if( d == DIRECTION_N || d == DIRECTION_NE || d == DIRECTION_NW ) { y--; } else if ( d == DIRECTION_S || d == DIRECTION_SE || d == DIRECTION_SW ) { y++; } return y; } char **make_grid(char **words, int height, int width, int simple, int count) { char **grid = init_grid(NULL, height, width); for(int i=0; imin_x, b->max_x); y = random_number(b->min_y, b->max_y); char** tempgrid = init_grid(grid, height, width); /* Now we have two copies of the grid, try to place the word... */ int i; for(i=0; i int main() { char *words[4] = { "test", "word", "longer", "verylong" }; char **grid = make_grid(words, 10, 10, 0, 4); print_grid(grid, 4); } #endif