X-Git-Url: https://harishankar.org/repos/?p=wordblah.git;a=blobdiff_plain;f=wordblox.h;fp=wordblox.h;h=e27d37cfbaeabe9b3f5b0e147e14a0e3f63d52e2;hp=f7a3ce4ae39f08eadbd96452aa85a15dd6af0ee8;hb=350edf3c909ce7926dc84411190cca003f6ac2e9;hpb=e9f447d1fbbf9c6098d6f3ea9c4695b60a68cead diff --git a/wordblox.h b/wordblox.h index f7a3ce4..e27d37c 100644 --- a/wordblox.h +++ b/wordblox.h @@ -69,6 +69,7 @@ typedef struct { char char_ans[MAX_PUZZLE_SIZE][MAX_PUZZLE_SIZE]; int cur_row; int cur_col; + enum ORIENTATION current_movement; } MainPlayerData; /* compute the hash of a password */ @@ -290,6 +291,46 @@ void reset_color () { printf ("\x1B[0m"); } +/* check if the prev row has a block or not */ +bool prev_row_block (Puzzle *p, int r, int c) +{ + if (r == 0) + return true; + if (p->chars[r-1][c] == '#') + return true; + return false; +} + +/* check if the next row has a block or not */ +bool next_row_block (Puzzle *p, int r, int c) +{ + if (r == p->grid_size-1) + return true; + if (p->chars[r+1][c] == '#') + return true; + return false; +} + +/* check if the prev col has a block or not */ +bool prev_col_block (Puzzle *p, int r, int c) +{ + if (c == 0) + return true; + if (p->chars[r][c-1] == '#') + return true; + return false; +} + +/* check if the next col has a block or not */ +bool next_col_block (Puzzle *p, int r, int c) +{ + if (c == p->grid_size - 1) + return true; + if (p->chars[r][c+1] == '#') + return true; + return false; +} + /* check if previous row is blank or not */ bool prev_row_blank (Puzzle *p, int r, int c) { @@ -319,6 +360,34 @@ bool next_col_blank (Puzzle *p, int r, int c) return false; } +/* set the current row/col to the beginning of word index (across or down) */ +void set_selection_to_word_start (MainPlayerData *app_data, + enum ORIENTATION orient, int word_index) +{ + for (int i = 0; i < app_data->puzzle.grid_size; i ++) + { + for (int j = 0; j < app_data->puzzle.grid_size; j ++) + { + if (orient == ACROSS && + app_data->puzzle.start_across_word[i][j] == word_index) + { + app_data->current_movement = ACROSS; + app_data->cur_row = i; + app_data->cur_col = j; + break; + } + else if (orient == DOWN && + app_data->puzzle.start_down_word[i][j] == word_index) + { + app_data->current_movement = DOWN; + app_data->cur_row = i; + app_data->cur_col = j; + break; + } + } + } +} + /* unfreeze the grid - make editing possible to change words */ void unfreeze_puzzle (Puzzle *p) {