X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/1185e3c5eaf5a0ac405e14939e7ee818914e0701..171fbdaa70df511fabad11a55abf98b57a6b03cb:/twiddle.c diff --git a/twiddle.c b/twiddle.c index 07a735f..f6c8f4d 100644 --- a/twiddle.c +++ b/twiddle.c @@ -308,7 +308,7 @@ static int grid_complete(int *grid, int wh, int orientable) } static char *new_game_desc(game_params *params, random_state *rs, - game_aux_info **aux) + game_aux_info **aux, int interactive) { int *grid; int w = params->w, h = params->h, n = params->n, wh = w*h; @@ -428,7 +428,7 @@ static char *validate_desc(game_params *params, char *desc) return NULL; } -static game_state *new_game(game_params *params, char *desc) +static game_state *new_game(midend_data *me, game_params *params, char *desc) { game_state *state = snew(game_state); int w = params->w, h = params->h, n = params->n, wh = w*h; @@ -594,6 +594,8 @@ static game_state *make_move(game_state *from, game_ui *ui, int x, int y, game_state *ret; int dir; + button = button & (~MOD_MASK | MOD_NUM_KEYPAD); + if (button == LEFT_BUTTON || button == RIGHT_BUTTON) { /* * Determine the coordinates of the click. We offset by n-1 @@ -604,30 +606,66 @@ static game_state *make_move(game_state *from, game_ui *ui, int x, int y, y -= (n-1) * TILE_SIZE / 2; x = FROMCOORD(x); y = FROMCOORD(y); - if (x < 0 || x > w-n || y < 0 || y > w-n) + dir = (button == LEFT_BUTTON ? 1 : -1); + if (x < 0 || x > w-n || y < 0 || y > h-n) return NULL; + } else if (button == 'a' || button == 'A' || button==MOD_NUM_KEYPAD+'7') { + x = y = 0; + dir = (button == 'A' ? -1 : +1); + } else if (button == 'b' || button == 'B' || button==MOD_NUM_KEYPAD+'9') { + x = w-n; + y = 0; + dir = (button == 'B' ? -1 : +1); + } else if (button == 'c' || button == 'C' || button==MOD_NUM_KEYPAD+'1') { + x = 0; + y = h-n; + dir = (button == 'C' ? -1 : +1); + } else if (button == 'd' || button == 'D' || button==MOD_NUM_KEYPAD+'3') { + x = w-n; + y = h-n; + dir = (button == 'D' ? -1 : +1); + } else if (button==MOD_NUM_KEYPAD+'8' && (w-n) % 2 == 0) { + x = (w-n) / 2; + y = 0; + dir = +1; + } else if (button==MOD_NUM_KEYPAD+'2' && (w-n) % 2 == 0) { + x = (w-n) / 2; + y = h-n; + dir = +1; + } else if (button==MOD_NUM_KEYPAD+'4' && (h-n) % 2 == 0) { + x = 0; + y = (h-n) / 2; + dir = +1; + } else if (button==MOD_NUM_KEYPAD+'6' && (h-n) % 2 == 0) { + x = w-n; + y = (h-n) / 2; + dir = +1; + } else if (button==MOD_NUM_KEYPAD+'5' && (w-n) % 2 == 0 && (h-n) % 2 == 0){ + x = (w-n) / 2; + y = (h-n) / 2; + dir = +1; + } else { + return NULL; /* no move to be made */ + } - /* - * This is a valid move. Make it. - */ - ret = dup_game(from); - ret->just_used_solve = FALSE; /* zero this in a hurry */ - ret->movecount++; - dir = (button == LEFT_BUTTON ? 1 : -1); - do_rotate(ret->grid, w, h, n, ret->orientable, x, y, dir); - ret->lastx = x; - ret->lasty = y; - ret->lastr = dir; + /* + * This is a valid move. Make it. + */ + ret = dup_game(from); + ret->just_used_solve = FALSE; /* zero this in a hurry */ + ret->movecount++; + do_rotate(ret->grid, w, h, n, ret->orientable, x, y, dir); + ret->lastx = x; + ret->lasty = y; + ret->lastr = dir; - /* - * See if the game has been completed. To do this we simply - * test that the grid contents are in increasing order. - */ - if (!ret->completed && grid_complete(ret->grid, wh, ret->orientable)) - ret->completed = ret->movecount; - return ret; - } - return NULL; + /* + * See if the game has been completed. To do this we simply + * test that the grid contents are in increasing order. + */ + if (!ret->completed && grid_complete(ret->grid, wh, ret->orientable)) + ret->completed = ret->movecount; + return ret; } /* ---------------------------------------------------------------------- @@ -904,7 +942,7 @@ static int highlight_colour(float angle) } static float game_anim_length(game_state *oldstate, game_state *newstate, - int dir) + int dir, game_ui *ui) { if ((dir > 0 && newstate->just_used_solve) || (dir < 0 && oldstate->just_used_solve)) @@ -914,7 +952,7 @@ static float game_anim_length(game_state *oldstate, game_state *newstate, } static float game_flash_length(game_state *oldstate, game_state *newstate, - int dir) + int dir, game_ui *ui) { if (!oldstate->completed && newstate->completed && !oldstate->used_solve && !newstate->used_solve) @@ -974,7 +1012,7 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate, */ if (oldstate) { float angle; - float anim_max = game_anim_length(oldstate, state, dir); + float anim_max = game_anim_length(oldstate, state, dir, ui); if (dir > 0) { lastx = state->lastx; @@ -1073,6 +1111,11 @@ static int game_wants_statusbar(void) return TRUE; } +static int game_timing_state(game_state *state) +{ + return TRUE; +} + #ifdef COMBINED #define thegame twiddle #endif @@ -1106,4 +1149,5 @@ const struct game thegame = { game_anim_length, game_flash_length, game_wants_statusbar, + FALSE, game_timing_state, };